Sha256: 7d58549b48bcf22e5b86d6e26b23e53e723681d7c5450b8e6dccdaa527e197a8

Contents?: true

Size: 1.3 KB

Versions: 1

Compression:

Stored size: 1.3 KB

Contents

# frozen_string_literal: true

# Copyright The OpenTelemetry Authors
#
# SPDX-License-Identifier: Apache-2.0

module OpenTelemetry
  module Instrumentation
    module AwsSdk
      # The MessageAttributeSetter class provides methods for writing tracing information to
      # SNS / SQS messages.
      #
      # @example
      #   OpenTelemetry.propagation.inject(context.params[:message_attributes], setter: MessageAttributeSetter)
      class MessageAttributeSetter
        def self.set(carrier, key, value)
          # https://docs.aws.amazon.com/AWSSimpleQueueService/latest/SQSDeveloperGuide/sqs-quotas.html
          if carrier.length < 10
            carrier[key] = { string_value: value, data_type: 'String' }
          else
            OpenTelemetry.logger.warn('aws-sdk instrumentation: cannot set context propagation on SQS/SNS message due to maximum amount of MessageAttributes')
          end
        end
      end

      # The MessageAttributeGetter class provides methods for getting tracing information from SQS message.
      #
      # @example
      #   OpenTelemetry.propagation.extract(message, getter: MessageAttributeGetter)
      class MessageAttributeGetter
        def self.get(carrier, key)
          carrier[key][:string_value] if carrier[key][:data_type] == 'String'
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
opentelemetry-instrumentation-aws_sdk-0.5.0 lib/opentelemetry/instrumentation/aws_sdk/message_attributes.rb