opentelemetry-ruby-contrib icon indicating copy to clipboard operation
opentelemetry-ruby-contrib copied to clipboard

Sqs processing spans

Open plantfansam opened this issue 3 years ago • 2 comments

This PR was originally in opentelemetry-ruby. Migrated it over to -contrib because we moved instrumentation here.

Original description from @YanivD follows:


This pr discussed as part of https://github.com/open-telemetry/opentelemetry-ruby/pull/1026


What's added in this PR?

  • Added config option extract_messaging_context disabled by default.
  • Extracting context propagation for SQS.ReceiveMessage method. In addition to the receive span, it creates an empty process span for every processed message, linking to the producer span.

Context propagation strategy

Currently SQS doesn't natively support propagating the OTEL context. Used JS aws-sdk instrumentation as an inspiration for this PR. It use message attributes to populate propagator fields.

Limitations

SQS support up to 10 message metadata attributes. Context fields will not be injected into the sqs message attributes if it will cause the limit to be reached.

Examples

Produce message span

#<struct OpenTelemetry::SDK::Trace::SpanData
 name="demo-topic send",
 kind=:producer,
 status=
  #<OpenTelemetry::Trace::Status:0x00007f9fd0960920 @code=1, @description="">,
 parent_span_id="\x00\x00\x00\x00\x00\x00\x00\x00",
 total_recorded_attributes=8,
 total_recorded_events=0,
 total_recorded_links=0,
 start_timestamp=1652257484971839000,
 end_timestamp=1652257485734213000,
 attributes=
  {"aws.region"=>"us-east-1",
   "rpc.system"=>"aws-api",
   "rpc.method"=>"Publish",
   "rpc.service"=>"SNS",
   "messaging.system"=>"aws.sns",
   "messaging.destination_kind"=>"topic",
   "messaging.destination"=>"demo-topic",
   "http.status_code"=>200},
 links=nil,
 events=nil,
 resource=
  #<OpenTelemetry::SDK::Resources::Resource:0x00007f9fcd29f620
   @attributes=
    {"service.name"=>"unknown_service",
     "process.pid"=>11398,
     "process.command"=>"trace_demonstration.rb",
     "process.runtime.name"=>"ruby",
     "process.runtime.version"=>"3.0.2",
     "process.runtime.description"=>
      "ruby 3.0.2p107 (2021-07-07 revision 0db68f0233) [x86_64-darwin19]",
     "telemetry.sdk.name"=>"opentelemetry",
     "telemetry.sdk.language"=>"ruby",
     "telemetry.sdk.version"=>"1.0.3"}>,
 instrumentation_library=
  #<struct OpenTelemetry::SDK::InstrumentationLibrary
   name="OpenTelemetry::Instrumentation::AwsSdk",
   version="0.2.3">,
 span_id="\x04\x05E5\xC2i\x01E",
 trace_id="\xF7\xADg\xC1Q\xDB\xE4\x95G\xBF\x01v\x8A\xD2\x0E\xDD",
 trace_flags=#<OpenTelemetry::Trace::TraceFlags:0x00007f9fcd2827c8 @flags=1>,
 tracestate=#<OpenTelemetry::Trace::Tracestate:0x00007f9fcd29f378 @hash={}>>

Consume message spans

#<struct OpenTelemetry::SDK::Trace::SpanData
 name="demo-queue process",
 kind=:consumer,
 status=
  #<OpenTelemetry::Trace::Status:0x00007f79229ec8c8 @code=1, @description="">,
 parent_span_id="\xBE\x19\xE6,\xD9\xF4\xEF\xFF",
 total_recorded_attributes=6,
 total_recorded_events=0,
 total_recorded_links=1,
 start_timestamp=1652257507902723000,
 end_timestamp=1652257507902740000,
 attributes=
  {"messaging.system"=>"aws.sqs",
   "messaging.destination"=>"demo-queue",
   "messaging.destination_kind"=>"queue",
   "messaging.message_id"=>"0a7d851d-c3fd-4149-827d-67f6923a9d95",
   "messaging.url"=>
    "https://sqs.us-east-1.amazonaws.com/731241200035/demo-queue",
   "messaging.operation"=>"process"},
 links=
  [#<OpenTelemetry::Trace::Link:0x00007f7922aa5f30
    @attributes={},
    @span_context=
     #<OpenTelemetry::Trace::SpanContext:0x00007f7922aa61b0
      @remote=true,
      @span_id="\x04\x05E5\xC2i\x01E",
      @trace_flags=
       #<OpenTelemetry::Trace::TraceFlags:0x00007f7922aa6430 @flags=1>,
      @trace_id="\xF7\xADg\xC1Q\xDB\xE4\x95G\xBF\x01v\x8A\xD2\x0E\xDD",
      @tracestate=
       #<OpenTelemetry::Trace::Tracestate:0x00007f792393f190 @hash={}>>>],
 events=nil,
 resource=
  #<OpenTelemetry::SDK::Resources::Resource:0x00007f792393d9f8
   @attributes=
    {"service.name"=>"unknown_service",
     "process.pid"=>11440,
     "process.command"=>"trace_demonstration.rb",
     "process.runtime.name"=>"ruby",
     "process.runtime.version"=>"3.0.2",
     "process.runtime.description"=>
      "ruby 3.0.2p107 (2021-07-07 revision 0db68f0233) [x86_64-darwin19]",
     "telemetry.sdk.name"=>"opentelemetry",
     "telemetry.sdk.language"=>"ruby",
     "telemetry.sdk.version"=>"1.0.3"}>,
 instrumentation_library=
  #<struct OpenTelemetry::SDK::InstrumentationLibrary
   name="OpenTelemetry::Instrumentation::AwsSdk",
   version="0.2.3">,
 span_id="&.(\xB1L\xC6\xB8K",
 trace_id="\x18\xDB\x0F7\x921$\fF\xCA\xD0\xABU`\xBB\x12",
 trace_flags=#<OpenTelemetry::Trace::TraceFlags:0x00007f7923926668 @flags=1>,
 tracestate=#<OpenTelemetry::Trace::Tracestate:0x00007f792393f190 @hash={}>>

#<struct OpenTelemetry::SDK::Trace::SpanData
 name="demo-queue receive",
 kind=:consumer,
 status=
  #<OpenTelemetry::Trace::Status:0x00007f79229ec8c8 @code=1, @description="">,
 parent_span_id="\x00\x00\x00\x00\x00\x00\x00\x00",
 total_recorded_attributes=10,
 total_recorded_events=0,
 total_recorded_links=0,
 start_timestamp=1652257507141648000,
 end_timestamp=1652257507904882000,
 attributes=
  {"aws.region"=>"us-east-1",
   "rpc.system"=>"aws-api",
   "rpc.method"=>"ReceiveMessage",
   "rpc.service"=>"SQS",
   "messaging.system"=>"aws.sqs",
   "messaging.destination_kind"=>"queue",
   "messaging.destination"=>"demo-queue",
   "messaging.url"=>
    "https://sqs.us-east-1.amazonaws.com/731241200035/demo-queue",
   "messaging.operation"=>"receive",
   "http.status_code"=>200},
 links=nil,
 events=nil,
 resource=
  #<OpenTelemetry::SDK::Resources::Resource:0x00007f792393d9f8
   @attributes=
    {"service.name"=>"unknown_service",
     "process.pid"=>11440,
     "process.command"=>"trace_demonstration.rb",
     "process.runtime.name"=>"ruby",
     "process.runtime.version"=>"3.0.2",
     "process.runtime.description"=>
      "ruby 3.0.2p107 (2021-07-07 revision 0db68f0233) [x86_64-darwin19]",
     "telemetry.sdk.name"=>"opentelemetry",
     "telemetry.sdk.language"=>"ruby",
     "telemetry.sdk.version"=>"1.0.3"}>,
 instrumentation_library=
  #<struct OpenTelemetry::SDK::InstrumentationLibrary
   name="OpenTelemetry::Instrumentation::AwsSdk",
   version="0.2.3">,
 span_id="\xBE\x19\xE6,\xD9\xF4\xEF\xFF",
 trace_id="\x18\xDB\x0F7\x921$\fF\xCA\xD0\xABU`\xBB\x12",
 trace_flags=#<OpenTelemetry::Trace::TraceFlags:0x00007f7923926668 @flags=1>,
 tracestate=#<OpenTelemetry::Trace::Tracestate:0x00007f792393f190 @hash={}>>

plantfansam avatar Jun 17 '22 17:06 plantfansam

@plantfansam to confirm... we are waiting on tests here right?

arielvalentin avatar Jun 22 '22 21:06 arielvalentin

@arielvalentin yes, exactly!

plantfansam avatar Jun 22 '22 22:06 plantfansam

👋 This pull request has been marked as stale because it has been open with no activity. You can: comment on the issue or remove the stale label to hold stale off for a while, add the keep label to hold stale off permanently, or do nothing. If you do nothing this pull request will be closed eventually by the stale bot

github-actions[bot] avatar Apr 27 '23 01:04 github-actions[bot]