Google-cloud-ruby: Stackdriver trace does not allow setting a service name?

Created on 15 Nov 2018  路  4Comments  路  Source: googleapis/google-cloud-ruby

As we have many applications on the gcloud - What's best practice to separate them for trace?
At least the ruby gem does not support a lot of options but the interface offers a filter for appengine serrvices?

cloudtrace question

Most helpful comment

I'm getting some more detailed information from the Stackdriver UI team, but here is some preliminary information.

(1) The App Engine Service and Version dropdowns are populated only if an actual App Engine service of that name and version is deployed. That's probably why you're not able to filter by them in the UI. In general, if you're actually deploying to App Engine, then this is the easiest way to filter by service. (And the trace library's middleware will automatically add those labels for you if you are running on App Engine.) But if not, move on to...
(2) Just use the request filter box. You can filter on arbitrary labels. So define your own label, set it to different values for different services. Then use the filter syntax to specify which label values to display.

That should be enough to get you started.

All 4 comments

Hi @tobsch, I have a request into Google asking for more information about best practices. Unfortunately, we only work on the Ruby gems in this repo, and aren't familiar with the UI. it might also be a good idea to ask about best practices on StackOverflow.

Here is what I have tried. You can set a label on your root span that will identify the service. To do this you pass in a Google::Cloud::Trace::LabelKey::GAE_APP_MODULE key and a String value of the service name. You can then filter on that label. Here is some code that does this.

require "google/cloud/trace"

class MyApp
  def foo
    Google::Cloud::Trace.in_span "MyApp.foo" do
      sleep rand(1.0..3.0)
      Foo.new.bar
    end
  end
end

class Foo
  def bar
    Google::Cloud::Trace.in_span "Foo.bar" do
      sleep rand(1.0..3.0)
      Bar.new.baz
    end
  end
end

class Bar
  def baz
    Google::Cloud::Trace.in_span "Bar.baz" do
      sleep rand(1.0..3.0)
    end
  end
end

# Create the trace and make the calls
trace_client = Google::Cloud::Trace.new
trace = trace_client.new_trace
Google::Cloud::Trace.set trace

Google::Cloud::Trace.in_span(
  "MyApp-5",
  labels: {
    Google::Cloud::Trace::LabelKey::GAE_APP_MODULE => "MyApp"
  }
) do
  MyApp.new.foo
end

trace_client.patch_traces trace

The Trace UI will recognize "MyApp" as the Service on the trace record, but it doesn't populate the Service dropdown in the UI header.

MyApp Service in the Trace UI

Does this answer your question?

@tobsch Ping.

@dazuma Any word on best practices for identifying applications in traces? Is this label the one to use?

I'm getting some more detailed information from the Stackdriver UI team, but here is some preliminary information.

(1) The App Engine Service and Version dropdowns are populated only if an actual App Engine service of that name and version is deployed. That's probably why you're not able to filter by them in the UI. In general, if you're actually deploying to App Engine, then this is the easiest way to filter by service. (And the trace library's middleware will automatically add those labels for you if you are running on App Engine.) But if not, move on to...
(2) Just use the request filter box. You can filter on arbitrary labels. So define your own label, set it to different values for different services. Then use the filter syntax to specify which label values to display.

That should be enough to get you started.

Was this page helpful?
0 / 5 - 0 ratings