Skip to content

Commit 03e36ce

Browse files
ahayworthfbogsany
andauthored
feat: support InstrumentationScope, and update OTLP proto to 0.18.0 (#1345)
* feat: support InstrumentationScope, and update OTLP proto to 0.18.0 This commit accomplishes two things simultaneously - adding support for InstrumentationScope everywhere, and also updating the OTLP proto to v0.18.0. The PR that introduced InstrumentationScope is [here](open-telemetry/opentelemetry-specification#2276) My best understanding (which is implemented in this PR) is that: - Our OTLP export requests should group by InstrumentationScope instead of InstrumentationLibrary - We must be able to support accessing the InstrumentationLibrary from anywhere a ReadableSpan is available, and that it should represent the `name` and `version` fields from the InstrumentationScope. - When creating a tracer, we create and store an InstrumentationScope rather than an InstrumentationLibrary. - Non-OTLP exporters must export both `otlp.scope.{name,version}` AND `otlp.library.{name,version}` tags for backwards compatibility. Some notes that may be interesting: - I chose to keep the original definition of `InstrumentationLibrary` around for now. - I chose to have `Span#instrumentation_library` and `SpanData#instrumentation_library` create and memoize an `InstrumentationLibrary` on-demand when someone asks for it (and marked the method as deprecated in the YARD docs). - I chose *not* to reference that deprecated helper when modifying the zipkin and jaeger exporters, for performance reasons. * Update sdk/test/opentelemetry/sdk/trace/span_test.rb Co-authored-by: Francis Bogsanyi <[email protected]> * Update sdk/lib/opentelemetry/sdk/trace/span_data.rb Co-authored-by: Francis Bogsanyi <[email protected]> * Update sdk/lib/opentelemetry/sdk/trace/span.rb Co-authored-by: Francis Bogsanyi <[email protected]> * fixup: use alias_method * fixup: add deprecation notice to InstrumentationLibrary * fixup: argh, use alias in class scope * Update sdk/lib/opentelemetry/sdk/trace/span.rb Co-authored-by: Francis Bogsanyi <[email protected]> * Update sdk/lib/opentelemetry/sdk/trace/span.rb Co-authored-by: Francis Bogsanyi <[email protected]> * Update sdk/lib/opentelemetry/sdk/trace/span_data.rb Co-authored-by: Francis Bogsanyi <[email protected]> * fixup: update Rakefile to regenerate protos correctly It now checks out a specific tag, for starters. * bundle exec rake update_protobuf Co-authored-by: Francis Bogsanyi <[email protected]>
1 parent 5b0cee9 commit 03e36ce

File tree

53 files changed

+325
-359
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+325
-359
lines changed

exporter/jaeger/lib/opentelemetry/exporter/jaeger/encoder.rb

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ def encoded_span(span_data) # rubocop:disable Metrics/MethodLength
7171
tags = encoded_tags(span_data.attributes) +
7272
encoded_status(span_data.status) +
7373
encoded_kind(span_data.kind) +
74-
encoded_instrumentation_library(span_data.instrumentation_library)
74+
encoded_instrumentation_scope(span_data.instrumentation_scope)
7575

7676
dropped_attributes_count = span_data.total_recorded_attributes - span_data.attributes&.size.to_i
7777
dropped_events_count = span_data.total_recorded_events - span_data.events&.size.to_i
@@ -141,12 +141,20 @@ def encoded_status(status)
141141
)
142142
end
143143

144-
def encoded_instrumentation_library(instrumentation_library)
145-
return EMPTY_ARRAY unless instrumentation_library
144+
def encoded_instrumentation_scope(instrumentation_scope)
145+
return EMPTY_ARRAY unless instrumentation_scope
146146

147147
tags = []
148-
tags << encoded_tag('otel.library.name', instrumentation_library.name) if instrumentation_library.name
149-
tags << encoded_tag('otel.library.version', instrumentation_library.version) if instrumentation_library.version
148+
if instrumentation_scope.name
149+
tags << encoded_tag('otel.scope.name', instrumentation_scope.name)
150+
tags << encoded_tag('otel.library.name', instrumentation_scope.name)
151+
end
152+
153+
if instrumentation_scope.version
154+
tags << encoded_tag('otel.scope.version', instrumentation_scope.version)
155+
tags << encoded_tag('otel.library.version', instrumentation_scope.version)
156+
end
157+
150158
tags
151159
end
152160

exporter/jaeger/test/opentelemetry/exporter/jaeger/encoder_test.rb

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -119,38 +119,47 @@
119119
)
120120
end
121121

122-
describe 'instrumentation library' do
123-
it 'encodes library and version when set' do
124-
lib = OpenTelemetry::SDK::InstrumentationLibrary.new('mylib', '0.1.0')
125-
span_data = create_span_data(instrumentation_library: lib)
122+
describe 'instrumentation scope' do
123+
it 'encodes name and version when set, with backwards-compat tags' do
124+
lib = OpenTelemetry::SDK::InstrumentationScope.new('mylib', '0.1.0')
125+
span_data = create_span_data(instrumentation_scope: lib)
126126
encoded_span = Encoder.encoded_span(span_data)
127127

128-
_(encoded_span.tags.size).must_equal(2)
128+
_(encoded_span.tags.size).must_equal(4)
129129

130-
name_tag, version_tag = encoded_span.tags
130+
name_tag, old_name_tag, version_tag, old_version_tag = encoded_span.tags
131131

132-
_(name_tag.key).must_equal('otel.library.name')
132+
_(name_tag.key).must_equal('otel.scope.name')
133133
_(name_tag.vStr).must_equal('mylib')
134134

135-
_(version_tag.key).must_equal('otel.library.version')
135+
_(old_name_tag.key).must_equal('otel.library.name')
136+
_(old_name_tag.vStr).must_equal('mylib')
137+
138+
_(version_tag.key).must_equal('otel.scope.version')
136139
_(version_tag.vStr).must_equal('0.1.0')
140+
141+
_(old_version_tag.key).must_equal('otel.library.version')
142+
_(old_version_tag.vStr).must_equal('0.1.0')
137143
end
138144

139145
it 'skips nil values' do
140-
lib = OpenTelemetry::SDK::InstrumentationLibrary.new('mylib')
141-
span_data = create_span_data(instrumentation_library: lib)
146+
lib = OpenTelemetry::SDK::InstrumentationScope.new('mylib')
147+
span_data = create_span_data(instrumentation_scope: lib)
142148
encoded_span = Encoder.encoded_span(span_data)
143149

144-
_(encoded_span.tags.size).must_equal(1)
150+
_(encoded_span.tags.size).must_equal(2)
145151

146-
name_tag, = encoded_span.tags
152+
name_tag, old_name_tag = encoded_span.tags
147153

148-
_(name_tag.key).must_equal('otel.library.name')
154+
_(name_tag.key).must_equal('otel.scope.name')
149155
_(name_tag.vStr).must_equal('mylib')
156+
157+
_(old_name_tag.key).must_equal('otel.library.name')
158+
_(old_name_tag.vStr).must_equal('mylib')
150159
end
151160
end
152161

153-
def create_span_data(status: nil, kind: nil, attributes: nil, total_recorded_attributes: 0, events: nil, total_recorded_events: 0, links: nil, total_recorded_links: 0, instrumentation_library: nil, trace_id: OpenTelemetry::Trace.generate_trace_id, trace_flags: OpenTelemetry::Trace::TraceFlags::DEFAULT, tracestate: nil)
162+
def create_span_data(status: nil, kind: nil, attributes: nil, total_recorded_attributes: 0, events: nil, total_recorded_events: 0, links: nil, total_recorded_links: 0, instrumentation_scope: nil, trace_id: OpenTelemetry::Trace.generate_trace_id, trace_flags: OpenTelemetry::Trace::TraceFlags::DEFAULT, tracestate: nil)
154163
OpenTelemetry::SDK::Trace::SpanData.new(
155164
'',
156165
kind,
@@ -165,7 +174,7 @@ def create_span_data(status: nil, kind: nil, attributes: nil, total_recorded_att
165174
links,
166175
events,
167176
nil,
168-
instrumentation_library,
177+
instrumentation_scope,
169178
OpenTelemetry::Trace.generate_span_id,
170179
trace_id,
171180
trace_flags,

exporter/jaeger/test/test_helper.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515

1616
def create_span_data(name: '', kind: nil, status: nil, parent_span_id: OpenTelemetry::Trace::INVALID_SPAN_ID,
1717
total_recorded_attributes: 0, total_recorded_events: 0, total_recorded_links: 0, start_timestamp: OpenTelemetry::TestHelpers.exportable_timestamp,
18-
end_timestamp: OpenTelemetry::TestHelpers.exportable_timestamp, attributes: nil, links: nil, events: nil, resource: nil, instrumentation_library: nil,
18+
end_timestamp: OpenTelemetry::TestHelpers.exportable_timestamp, attributes: nil, links: nil, events: nil, resource: nil, instrumentation_scope: nil,
1919
span_id: OpenTelemetry::Trace.generate_span_id, trace_id: OpenTelemetry::Trace.generate_trace_id,
2020
trace_flags: OpenTelemetry::Trace::TraceFlags::DEFAULT, tracestate: nil)
2121
OpenTelemetry::SDK::Trace::SpanData.new(name, kind, status, parent_span_id, total_recorded_attributes,
2222
total_recorded_events, total_recorded_links, start_timestamp, end_timestamp,
23-
attributes, links, events, resource, instrumentation_library, span_id, trace_id, trace_flags, tracestate)
23+
attributes, links, events, resource, instrumentation_scope, span_id, trace_id, trace_flags, tracestate)
2424
end

exporter/otlp-common/Rakefile

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,21 @@ else
2929
task default: %i[test rubocop yard]
3030
end
3131

32+
PROTO_VERSION = 'v0.18.0'
3233
PROTOBUF_FILES = [
34+
'collector/logs/v1/logs_service.proto',
35+
'collector/metrics/v1/metrics_service.proto',
36+
'collector/trace/v1/trace_service.proto',
3337
'common/v1/common.proto',
38+
'logs/v1/logs.proto',
39+
'metrics/v1/metrics.proto',
3440
'resource/v1/resource.proto',
3541
'trace/v1/trace.proto',
36-
'collector/trace/v1/trace_service.proto'
42+
'trace/v1/trace_config.proto'
3743
].freeze
3844

3945
task :update_protobuf do
40-
system('git clone https://github.com/open-telemetry/opentelemetry-proto')
46+
system("git clone -b #{PROTO_VERSION} https://github.com/open-telemetry/opentelemetry-proto")
4147
PROTOBUF_FILES.each do |file|
4248
system("protoc --ruby_out=lib/ --proto_path=opentelemetry-proto opentelemetry/proto/#{file}")
4349
end

exporter/otlp-common/lib/opentelemetry/exporter/otlp/common.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,11 @@ def as_etsr(span_data) # rubocop:disable Metrics/MethodLength
5252
resource: Opentelemetry::Proto::Resource::V1::Resource.new(
5353
attributes: resource.attribute_enumerator.map { |key, value| as_otlp_key_value(key, value) }
5454
),
55-
instrumentation_library_spans: span_datas
56-
.group_by(&:instrumentation_library)
55+
scope_spans: span_datas
56+
.group_by(&:instrumentation_scope)
5757
.map do |il, sds|
58-
Opentelemetry::Proto::Trace::V1::InstrumentationLibrarySpans.new(
59-
instrumentation_library: Opentelemetry::Proto::Common::V1::InstrumentationLibrary.new(
58+
Opentelemetry::Proto::Trace::V1::ScopeSpans.new(
59+
scope: Opentelemetry::Proto::Common::V1::InstrumentationScope.new(
6060
name: il.name,
6161
version: il.version
6262
),

exporter/otlp-common/lib/opentelemetry/proto/collector/logs/v1/logs_service_pb.rb

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

exporter/otlp-common/lib/opentelemetry/proto/collector/logs/v1/logs_service_services_pb.rb

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

exporter/otlp-common/lib/opentelemetry/proto/collector/metrics/v1/metrics_service_pb.rb

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

exporter/otlp-common/lib/opentelemetry/proto/collector/metrics/v1/metrics_service_services_pb.rb

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

exporter/otlp-common/lib/opentelemetry/proto/collector/trace/v1/trace_service_pb.rb

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)