Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 3c680cb

Browse files
author
Alex Boten
authored
Merge branch 'main' into codeboten/more-docs-improvements
2 parents 24b2101 + 7647a11 commit 3c680cb

File tree

37 files changed

+420
-305
lines changed

37 files changed

+420
-305
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1414
instruments to `NoOpCounter`, `NoOpHistogram`, `NoOpObservableCounter`,
1515
`NoOpObservableGauge`, `NoOpObservableUpDownCounter`, `NoOpUpDownCounter`
1616
([#2616](https://github.com/open-telemetry/opentelemetry-python/pull/2616))
17+
- Deprecate InstrumentationLibraryInfo and Add InstrumentationScope
18+
([#2583](https://github.com/open-telemetry/opentelemetry-python/pull/2583))
1719

1820
## [1.11.0-0.30b0](https://github.com/open-telemetry/opentelemetry-python/releases/tag/v1.11.0-0.30b0) - 2022-04-18
1921

exporter/opentelemetry-exporter-jaeger-proto-grpc/src/opentelemetry/exporter/jaeger/proto/grpc/translate/__init__.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535

3636
NAME_KEY = "otel.library.name"
3737
VERSION_KEY = "otel.library.version"
38+
_SCOPE_NAME_KEY = "otel.scope.name"
39+
_SCOPE_VERSION_KEY = "otel.scope.version"
3840

3941

4042
def _nsec_to_usec_round(nsec: int) -> int:
@@ -299,15 +301,22 @@ def _extract_tags(
299301
)
300302
)
301303

302-
# Instrumentation info KeyValues
303-
if span.instrumentation_info:
304+
# Instrumentation scope KeyValues
305+
if span.instrumentation_scope:
304306
name = _get_string_key_value(
305-
NAME_KEY, span.instrumentation_info.name
307+
NAME_KEY, span.instrumentation_scope.name
306308
)
307309
version = _get_string_key_value(
308-
VERSION_KEY, span.instrumentation_info.version
310+
VERSION_KEY, span.instrumentation_scope.version
311+
)
312+
scope_name = _get_string_key_value(
313+
_SCOPE_NAME_KEY, span.instrumentation_scope.name
314+
)
315+
scope_version = _get_string_key_value(
316+
_SCOPE_VERSION_KEY, span.instrumentation_scope.version
309317
)
310318
translated.extend([name, version])
319+
translated.extend([scope_name, scope_version])
311320

312321
# Make sure to add "error" tag if span status is not OK
313322
if not span.status.is_ok:

exporter/opentelemetry-exporter-jaeger-proto-grpc/tests/test_jaeger_exporter_protobuf.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
# pylint:disable=import-error
2626
from opentelemetry.exporter.jaeger.proto.grpc.gen import model_pb2
2727
from opentelemetry.exporter.jaeger.proto.grpc.translate import (
28+
_SCOPE_NAME_KEY,
29+
_SCOPE_VERSION_KEY,
2830
NAME_KEY,
2931
VERSION_KEY,
3032
Translate,
@@ -39,7 +41,7 @@
3941
from opentelemetry.sdk.resources import SERVICE_NAME, Resource
4042
from opentelemetry.sdk.trace import TracerProvider
4143
from opentelemetry.sdk.trace.export import SpanExportResult
42-
from opentelemetry.sdk.util.instrumentation import InstrumentationInfo
44+
from opentelemetry.sdk.util.instrumentation import InstrumentationScope
4345
from opentelemetry.test.spantestutil import (
4446
get_span_with_dropped_attributes_events_links,
4547
)
@@ -188,7 +190,7 @@ def test_translate_to_jaeger(self):
188190
context=other_context,
189191
parent=None,
190192
resource=Resource({}),
191-
instrumentation_info=InstrumentationInfo(
193+
instrumentation_scope=InstrumentationScope(
192194
name="name", version="version"
193195
),
194196
),
@@ -391,6 +393,16 @@ def test_translate_to_jaeger(self):
391393
v_type=model_pb2.ValueType.STRING,
392394
v_str="version",
393395
),
396+
model_pb2.KeyValue(
397+
key=_SCOPE_NAME_KEY,
398+
v_type=model_pb2.ValueType.STRING,
399+
v_str="name",
400+
),
401+
model_pb2.KeyValue(
402+
key=_SCOPE_VERSION_KEY,
403+
v_type=model_pb2.ValueType.STRING,
404+
v_str="version",
405+
),
394406
],
395407
process=model_pb2.Process(
396408
service_name="svc",

exporter/opentelemetry-exporter-jaeger-thrift/src/opentelemetry/exporter/jaeger/thrift/translate/__init__.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232

3333
NAME_KEY = "otel.library.name"
3434
VERSION_KEY = "otel.library.version"
35+
_SCOPE_NAME_KEY = "otel.scope.name"
36+
_SCOPE_VERSION_KEY = "otel.scope.version"
3537

3638

3739
def _nsec_to_usec_round(nsec: int) -> int:
@@ -220,12 +222,20 @@ def _extract_tags(self, span: ReadableSpan) -> Sequence[TCollector.Tag]:
220222
)
221223

222224
# Instrumentation info tags
223-
if span.instrumentation_info:
224-
name = _get_string_tag(NAME_KEY, span.instrumentation_info.name)
225+
if span.instrumentation_scope:
226+
name = _get_string_tag(NAME_KEY, span.instrumentation_scope.name)
225227
version = _get_string_tag(
226-
VERSION_KEY, span.instrumentation_info.version
228+
VERSION_KEY, span.instrumentation_scope.version
227229
)
230+
scope_name = _get_string_tag(
231+
_SCOPE_NAME_KEY, span.instrumentation_scope.name
232+
)
233+
scope_version = _get_string_tag(
234+
_SCOPE_VERSION_KEY, span.instrumentation_scope.version
235+
)
236+
228237
translated.extend([name, version])
238+
translated.extend([scope_name, scope_version])
229239

230240
# Make sure to add "error" tag if span status is not OK
231241
if not span.status.is_ok:

exporter/opentelemetry-exporter-jaeger-thrift/tests/test_jaeger_exporter_thrift.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
)
3737
from opentelemetry.sdk.resources import SERVICE_NAME
3838
from opentelemetry.sdk.trace import Resource, TracerProvider
39-
from opentelemetry.sdk.util.instrumentation import InstrumentationInfo
39+
from opentelemetry.sdk.util.instrumentation import InstrumentationScope
4040
from opentelemetry.test.globals_test import TraceGlobalsTest
4141
from opentelemetry.test.spantestutil import (
4242
get_span_with_dropped_attributes_events_links,
@@ -303,7 +303,7 @@ def test_translate_to_jaeger(self):
303303
context=other_context,
304304
parent=None,
305305
resource=Resource({}),
306-
instrumentation_info=InstrumentationInfo(
306+
instrumentation_scope=InstrumentationScope(
307307
name="name", version="version"
308308
),
309309
),
@@ -461,6 +461,16 @@ def test_translate_to_jaeger(self):
461461
vType=jaeger.TagType.STRING,
462462
vStr="version",
463463
),
464+
jaeger.Tag(
465+
key=jaeger_exporter.translate._SCOPE_NAME_KEY,
466+
vType=jaeger.TagType.STRING,
467+
vStr="name",
468+
),
469+
jaeger.Tag(
470+
key=jaeger_exporter.translate._SCOPE_VERSION_KEY,
471+
vType=jaeger.TagType.STRING,
472+
vStr="version",
473+
),
464474
],
465475
),
466476
]

exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/_log_exporter/__init__.py

Lines changed: 21 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@
2424
from opentelemetry.proto.collector.logs.v1.logs_service_pb2_grpc import (
2525
LogsServiceStub,
2626
)
27-
from opentelemetry.proto.common.v1.common_pb2 import InstrumentationLibrary
27+
from opentelemetry.proto.common.v1.common_pb2 import InstrumentationScope
2828
from opentelemetry.proto.logs.v1.logs_pb2 import (
29-
InstrumentationLibraryLogs,
29+
ScopeLogs,
3030
ResourceLogs,
3131
)
3232
from opentelemetry.proto.logs.v1.logs_pb2 import LogRecord as PB2LogRecord
@@ -96,44 +96,30 @@ def _translate_data(
9696
) -> ExportLogsServiceRequest:
9797
# pylint: disable=attribute-defined-outside-init
9898

99-
sdk_resource_instrumentation_library_logs = {}
99+
sdk_resource_scope_logs = {}
100100

101101
for log_data in data:
102102
resource = log_data.log_record.resource
103103

104-
instrumentation_library_logs_map = (
105-
sdk_resource_instrumentation_library_logs.get(resource, {})
106-
)
107-
if not instrumentation_library_logs_map:
108-
sdk_resource_instrumentation_library_logs[
109-
resource
110-
] = instrumentation_library_logs_map
111-
112-
instrumentation_library_logs = (
113-
instrumentation_library_logs_map.get(
114-
log_data.instrumentation_info
115-
)
116-
)
117-
if not instrumentation_library_logs:
118-
if log_data.instrumentation_info is not None:
119-
instrumentation_library_logs_map[
120-
log_data.instrumentation_info
121-
] = InstrumentationLibraryLogs(
122-
instrumentation_library=InstrumentationLibrary(
123-
name=log_data.instrumentation_info.name,
124-
version=log_data.instrumentation_info.version,
104+
scope_logs_map = sdk_resource_scope_logs.get(resource, {})
105+
if not scope_logs_map:
106+
sdk_resource_scope_logs[resource] = scope_logs_map
107+
108+
scope_logs = scope_logs_map.get(log_data.instrumentation_scope)
109+
if not scope_logs:
110+
if log_data.instrumentation_scope is not None:
111+
scope_logs_map[log_data.instrumentation_scope] = ScopeLogs(
112+
scope=InstrumentationScope(
113+
name=log_data.instrumentation_scope.name,
114+
version=log_data.instrumentation_scope.version,
125115
)
126116
)
127117
else:
128-
instrumentation_library_logs_map[
129-
log_data.instrumentation_info
130-
] = InstrumentationLibraryLogs()
131-
132-
instrumentation_library_logs = (
133-
instrumentation_library_logs_map.get(
134-
log_data.instrumentation_info
135-
)
136-
)
118+
scope_logs_map[
119+
log_data.instrumentation_scope
120+
] = ScopeLogs()
121+
122+
scope_logs = scope_logs_map.get(log_data.instrumentation_scope)
137123

138124
self._collector_kwargs = {}
139125

@@ -151,13 +137,13 @@ def _translate_data(
151137
"severity_number"
152138
] = log_data.log_record.severity_number.value
153139

154-
instrumentation_library_logs.log_records.append(
140+
scope_logs.log_records.append(
155141
PB2LogRecord(**self._collector_kwargs)
156142
)
157143

158144
return ExportLogsServiceRequest(
159145
resource_logs=get_resource_data(
160-
sdk_resource_instrumentation_library_logs,
146+
sdk_resource_scope_logs,
161147
ResourceLogs,
162148
"logs",
163149
)

exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/_metric_exporter/__init__.py

Lines changed: 20 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
from opentelemetry.proto.collector.metrics.v1.metrics_service_pb2_grpc import (
2626
MetricsServiceStub,
2727
)
28-
from opentelemetry.proto.common.v1.common_pb2 import InstrumentationLibrary
28+
from opentelemetry.proto.common.v1.common_pb2 import InstrumentationScope
2929
from opentelemetry.proto.metrics.v1 import metrics_pb2 as pb2
3030
from opentelemetry.sdk.environment_variables import (
3131
OTEL_EXPORTER_OTLP_METRICS_INSECURE,
@@ -81,40 +81,30 @@ def __init__(
8181
def _translate_data(
8282
self, data: Sequence[Metric]
8383
) -> ExportMetricsServiceRequest:
84-
sdk_resource_instrumentation_library_metrics = {}
84+
sdk_resource_scope_metrics = {}
8585

8686
for metric in data:
8787
resource = metric.resource
88-
instrumentation_library_map = (
89-
sdk_resource_instrumentation_library_metrics.get(resource, {})
90-
)
91-
if not instrumentation_library_map:
92-
sdk_resource_instrumentation_library_metrics[
93-
resource
94-
] = instrumentation_library_map
95-
96-
instrumentation_library_metrics = instrumentation_library_map.get(
97-
metric.instrumentation_info
98-
)
99-
100-
if not instrumentation_library_metrics:
101-
if metric.instrumentation_info is not None:
102-
instrumentation_library_map[
103-
metric.instrumentation_info
104-
] = pb2.InstrumentationLibraryMetrics(
105-
instrumentation_library=InstrumentationLibrary(
106-
name=metric.instrumentation_info.name,
107-
version=metric.instrumentation_info.version,
88+
scope_map = sdk_resource_scope_metrics.get(resource, {})
89+
if not scope_map:
90+
sdk_resource_scope_metrics[resource] = scope_map
91+
92+
scope_metrics = scope_map.get(metric.instrumentation_scope)
93+
94+
if not scope_metrics:
95+
if metric.instrumentation_scope is not None:
96+
scope_map[metric.instrumentation_scope] = pb2.ScopeMetrics(
97+
scope=InstrumentationScope(
98+
name=metric.instrumentation_scope.name,
99+
version=metric.instrumentation_scope.version,
108100
)
109101
)
110102
else:
111-
instrumentation_library_map[
112-
metric.instrumentation_info
113-
] = pb2.InstrumentationLibraryMetrics()
103+
scope_map[
104+
metric.instrumentation_scope
105+
] = pb2.ScopeMetrics()
114106

115-
instrumentation_library_metrics = instrumentation_library_map.get(
116-
metric.instrumentation_info
117-
)
107+
scope_metrics = scope_map.get(metric.instrumentation_scope)
118108

119109
pbmetric = pb2.Metric(
120110
name=metric.name,
@@ -167,12 +157,12 @@ def _translate_data(
167157
logger.warn("unsupported datapoint type %s", metric.point)
168158
continue
169159

170-
instrumentation_library_metrics.metrics.append(
160+
scope_metrics.metrics.append(
171161
pbmetric,
172162
)
173163
return ExportMetricsServiceRequest(
174164
resource_metrics=get_resource_data(
175-
sdk_resource_instrumentation_library_metrics,
165+
sdk_resource_scope_metrics,
176166
pb2.ResourceMetrics,
177167
"metrics",
178168
)

exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/exporter.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,7 @@ def _translate_key_values(key: str, value: Any) -> KeyValue:
126126

127127

128128
def get_resource_data(
129-
sdk_resource_instrumentation_library_data: Dict[
130-
SDKResource, ResourceDataT
131-
],
129+
sdk_resource_scope_data: Dict[SDKResource, ResourceDataT],
132130
resource_class: Callable[..., TypingResourceT],
133131
name: str,
134132
) -> List[TypingResourceT]:
@@ -137,8 +135,8 @@ def get_resource_data(
137135

138136
for (
139137
sdk_resource,
140-
instrumentation_library_data,
141-
) in sdk_resource_instrumentation_library_data.items():
138+
scope_data,
139+
) in sdk_resource_scope_data.items():
142140

143141
collector_resource = Resource()
144142

@@ -156,9 +154,7 @@ def get_resource_data(
156154
resource_class(
157155
**{
158156
"resource": collector_resource,
159-
"instrumentation_library_{}".format(
160-
name
161-
): instrumentation_library_data.values(),
157+
"scope_{}".format(name): scope_data.values(),
162158
}
163159
)
164160
)

0 commit comments

Comments
 (0)