Extract `otel.foo` to constants throughout the codebase
We have a sprinkling of otel.foo kinds of tags being used throughout the codebase:
opentelemetry-ruby on ahayworth/add-dropped-counts-zipkin-jaeger via 💎 v3.1.1
zsh ❯ git grep 'otel\.' | egrep -v '\/test\/'
exporter/jaeger/lib/opentelemetry/exporter/jaeger/encoder.rb: tags << encoded_tag('otel.dropped_attributes_count', dropped_attributes_count) if dropped_attributes_count.positive?
exporter/jaeger/lib/opentelemetry/exporter/jaeger/encoder.rb: tags << encoded_tag('otel.dropped_events_count', dropped_events_count) if dropped_events_count.positive?
exporter/jaeger/lib/opentelemetry/exporter/jaeger/encoder.rb: tags << encoded_tag('otel.dropped_links_count', dropped_links_count) if dropped_links_count.positive?
exporter/jaeger/lib/opentelemetry/exporter/jaeger/encoder.rb: tags << encoded_tag('otel.library.name', instrumentation_library.name) if instrumentation_library.name
exporter/jaeger/lib/opentelemetry/exporter/jaeger/encoder.rb: tags << encoded_tag('otel.library.version', instrumentation_library.version) if instrumentation_library.version
exporter/otlp-http/lib/opentelemetry/exporter/otlp/http/exporter.rb: @metrics_reporter.add_to_counter('otel.otlp_exporter.failure', labels: { 'reason' => response.code })
exporter/otlp-http/lib/opentelemetry/exporter/otlp/http/exporter.rb: @metrics_reporter.add_to_counter('otel.otlp_exporter.failure', labels: { 'reason' => e.class.to_s })
exporter/otlp-http/lib/opentelemetry/exporter/otlp/http/exporter.rb: @metrics_reporter.record_value('otel.otlp_exporter.request_duration',
exporter/otlp-http/lib/opentelemetry/exporter/otlp/http/exporter.rb: @metrics_reporter.add_to_counter('otel.otlp_exporter.failure', labels: { 'reason' => reason })
exporter/otlp/lib/opentelemetry/exporter/otlp/exporter.rb: @metrics_reporter.add_to_counter('otel.otlp_exporter.failure', labels: { 'reason' => response.code })
exporter/otlp/lib/opentelemetry/exporter/otlp/exporter.rb: @metrics_reporter.add_to_counter('otel.otlp_exporter.failure', labels: { 'reason' => e.class.to_s })
exporter/otlp/lib/opentelemetry/exporter/otlp/exporter.rb: @metrics_reporter.record_value('otel.otlp_exporter.request_duration',
exporter/otlp/lib/opentelemetry/exporter/otlp/exporter.rb: @metrics_reporter.add_to_counter('otel.otlp_exporter.failure', labels: { 'reason' => reason })
exporter/zipkin/lib/opentelemetry/exporter/zipkin/transformer.rb: STATUS_CODE_NAME = 'otel.status_code'
exporter/zipkin/lib/opentelemetry/exporter/zipkin/transformer.rb: tags['otel.library.name'] = span_data.instrumentation_library.name
exporter/zipkin/lib/opentelemetry/exporter/zipkin/transformer.rb: tags['otel.library.version'] = span_data.instrumentation_library.version
exporter/zipkin/lib/opentelemetry/exporter/zipkin/transformer.rb: tags['otel.dropped_attributes_count'] = dropped_attributes_count.to_s if dropped_attributes_count.positive?
exporter/zipkin/lib/opentelemetry/exporter/zipkin/transformer.rb: tags['otel.dropped_events_count'] = dropped_events_count.to_s if dropped_events_count.positive?
exporter/zipkin/lib/opentelemetry/exporter/zipkin/transformer.rb: tags['otel.dropped_links_count'] = dropped_links_count.to_s if dropped_links_count.positive?
sdk/lib/opentelemetry/sdk/trace/export/batch_span_processor.rb: @metrics_reporter.observe_value('otel.bsp.buffer_utilization', value: spans.size / max_queue_size.to_f)
sdk/lib/opentelemetry/sdk/trace/export/batch_span_processor.rb: @metrics_reporter.add_to_counter('otel.bsp.error', labels: { 'reason' => 'ThreadError' })
sdk/lib/opentelemetry/sdk/trace/export/batch_span_processor.rb: @metrics_reporter.add_to_counter('otel.bsp.error', labels: { 'reason' => e.class.to_s })
sdk/lib/opentelemetry/sdk/trace/export/batch_span_processor.rb: @metrics_reporter.add_to_counter('otel.bsp.export.success')
sdk/lib/opentelemetry/sdk/trace/export/batch_span_processor.rb: @metrics_reporter.add_to_counter('otel.bsp.exported_spans', increment: batch.size)
sdk/lib/opentelemetry/sdk/trace/export/batch_span_processor.rb: @metrics_reporter.add_to_counter('otel.bsp.export.failure')
sdk/lib/opentelemetry/sdk/trace/export/batch_span_processor.rb: @metrics_reporter.add_to_counter('otel.bsp.dropped_spans', increment: count, labels: { 'reason' => reason })
We should extract those to constants (perhaps living in opentelemetry-semantic_conventions), and use the constants throughout rather than assuming we won't make silly typos in the future!
cc #1235
Hello @ahayworth!, I'm new here and would love to contribute :).
I was taking a look at this issue and it seems very straightforward if you know all the components of OTLP. The thing is, I'm having a bit of trouble trying to guess (my guess is I shouldn't be guessing 😂 ) if it would make sense for the otel.* reserved attributes to live under semantic_conventions/lib/opentelemetry/semantic_conventions/common.rb and be called like SemanticConventions::Common::OTEL_JAEGER_EXPORTER_REQUEST_DURATION, for example.
Do you think this would make sense?
Thanks!
I think something like that would be perfectly fine, yes. I don't know if they need to be jaeger-specific though (we also do this for zipkin I think)
Oki doki!, thanks for the quick reply.
Will give it a try.
👋 This issue 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 issue will be closed eventually by the stale bot.