Skip to content

Instantly share code, notes, and snippets.

@pior
Created February 13, 2017 16:30
Show Gist options
  • Select an option

  • Save pior/f2bd839925bbeb1cde5ca4202f3d3311 to your computer and use it in GitHub Desktop.

Select an option

Save pior/f2bd839925bbeb1cde5ca4202f3d3311 to your computer and use it in GitHub Desktop.
require 'securerandom'
require 'date'
require 'googleauth'
require 'google/apis/cloudtrace_v1'
service = Google::Apis::CloudtraceV1::CloudTraceService.new
service.authorization = Google::Auth.get_application_default(['https://www.googleapis.com/auth/trace.append'])
project_id = 'XXXXX'
t1 = Time.now.utc.round(10).iso8601(6)
sleep 0.05
t2 = Time.now.utc.round(10).iso8601(6)
span = Google::Apis::CloudtraceV1::TraceSpan.new(
name: '/test',
span_id: 1.to_s,
start_time: t1,
end_time: t2,
labels: {},
kind: 'RPC_SERVER',
)
trace = Google::Apis::CloudtraceV1::Trace.new(
trace_id: SecureRandom.uuid.split('-').join,
project_id: project_id,
spans: [span]
)
traces = Google::Apis::CloudtraceV1::Traces.new(traces: [trace])
response = service.patch_project_traces(project_id, traces)
puts response.inspect