Skip to content

Commit f9e0c8d

Browse files
committed
resolved merge conflicts
1 parent a77ba74 commit f9e0c8d

30 files changed

Lines changed: 1051 additions & 180 deletions

File tree

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1313
## Unreleased
1414

1515
- Enabled the flake8-type-checking plugin rules for ruff linter. These rules do not allow the import of python objects outside the type-checking block, if they are only used for type annotations and are not used at runtime. ([#5029](https://github.com/open-telemetry/opentelemetry-python/pull/5029))
16+
- `opentelemetry-sdk`: Add shared `_parse_headers` helper for declarative config OTLP exporters
17+
([#5021](https://github.com/open-telemetry/opentelemetry-python/pull/5021))
1618
- `opentelemetry-api`: Replace a broad exception in attribute cleaning tests to satisfy pylint in the `lint-opentelemetry-api` CI job
1719
- `opentelemetry-sdk`: Add `create_resource` and `create_propagator`/`configure_propagator` to declarative file configuration, enabling Resource and propagator instantiation from config files without reading env vars
1820
([#4979](https://github.com/open-telemetry/opentelemetry-python/pull/4979))
@@ -42,6 +44,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
4244
([#4910](https://github.com/open-telemetry/opentelemetry-python/pull/4910))
4345
- Add configurable `max_export_batch_size` to OTLP HTTP metrics exporter
4446
([#4576](https://github.com/open-telemetry/opentelemetry-python/pull/4576))
47+
- `opentelemetry-sdk`: Implement experimental Meter configurator
48+
([#4966](https://github.com/open-telemetry/opentelemetry-python/pull/4966))
49+
- `opentelemetry-exporter-otlp-proto-http`: use consistent protobuf for export request
50+
([#5015](https://github.com/open-telemetry/opentelemetry-python/pull/5015))
51+
- `opentelemetry-sdk`: cache TracerConfig into the tracer, this changes an internal interface. Only one Tracer with the same instrumentation scope will be created
52+
([#5007](https://github.com/open-telemetry/opentelemetry-python/pull/5007))
4553

4654
## Version 1.40.0/0.61b0 (2026-03-04)
4755

docs/conf.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -228,11 +228,11 @@
228228
scm_web = "https://github.com/" + REPO + "blob/" + branch
229229

230230
# Store variables in the epilogue so they are globally available.
231-
rst_epilog = """
232-
.. |SCM_WEB| replace:: {s}
233-
.. |SCM_RAW_WEB| replace:: {sr}
234-
.. |SCM_BRANCH| replace:: {b}
235-
""".format(s=scm_web, sr=scm_raw_web, b=branch)
231+
rst_epilog = f"""
232+
.. |SCM_WEB| replace:: {scm_web}
233+
.. |SCM_RAW_WEB| replace:: {scm_raw_web}
234+
.. |SCM_BRANCH| replace:: {branch}
235+
"""
236236

237237
# used to have links to repo files
238238
extlinks = {

exporter/opentelemetry-exporter-otlp-proto-common/src/opentelemetry/exporter/otlp/proto/common/_internal/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ def _get_resource_data(
173173
resource_class(
174174
**{
175175
"resource": collector_resource,
176-
"scope_{}".format(name): scope_data.values(),
176+
f"scope_{name}": scope_data.values(),
177177
}
178178
)
179179
)

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,7 @@
155155
class InvalidCompressionValueException(Exception):
156156
def __init__(self, environ_key: str, environ_value: str):
157157
super().__init__(
158-
'Invalid value "{}" for compression envvar {}'.format(
159-
environ_value, environ_key
160-
)
158+
f'Invalid value "{environ_value}" for compression envvar {environ_key}'
161159
)
162160

163161

exporter/opentelemetry-exporter-otlp-proto-http/src/opentelemetry/exporter/otlp/proto/http/_common/__init__.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,6 @@
1919

2020
from opentelemetry.sdk.environment_variables import (
2121
_OTEL_PYTHON_EXPORTER_OTLP_HTTP_CREDENTIAL_PROVIDER,
22-
_OTEL_PYTHON_EXPORTER_OTLP_HTTP_LOGS_CREDENTIAL_PROVIDER,
23-
_OTEL_PYTHON_EXPORTER_OTLP_HTTP_METRICS_CREDENTIAL_PROVIDER,
24-
_OTEL_PYTHON_EXPORTER_OTLP_HTTP_TRACES_CREDENTIAL_PROVIDER,
2522
)
2623
from opentelemetry.util._importlib_metadata import entry_points
2724

@@ -36,9 +33,9 @@ def _is_retryable(resp: requests.Response) -> bool:
3633

3734
def _load_session_from_envvar(
3835
cred_envvar: Literal[
39-
_OTEL_PYTHON_EXPORTER_OTLP_HTTP_LOGS_CREDENTIAL_PROVIDER,
40-
_OTEL_PYTHON_EXPORTER_OTLP_HTTP_TRACES_CREDENTIAL_PROVIDER,
41-
_OTEL_PYTHON_EXPORTER_OTLP_HTTP_METRICS_CREDENTIAL_PROVIDER,
36+
"OTEL_PYTHON_EXPORTER_OTLP_HTTP_LOGS_CREDENTIAL_PROVIDER",
37+
"OTEL_PYTHON_EXPORTER_OTLP_HTTP_TRACES_CREDENTIAL_PROVIDER",
38+
"OTEL_PYTHON_EXPORTER_OTLP_HTTP_METRICS_CREDENTIAL_PROVIDER",
4239
],
4340
) -> Optional[requests.Session]:
4441
_credential_env = environ.get(

exporter/opentelemetry-exporter-otlp-proto-http/src/opentelemetry/exporter/otlp/proto/http/metric_exporter/__init__.py

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
_is_retryable,
5252
_load_session_from_envvar,
5353
)
54-
from opentelemetry.proto.collector.metrics.v1.metrics_service_pb2 import ( # noqa: F401
54+
from opentelemetry.proto.collector.metrics.v1.metrics_service_pb2 import (
5555
ExportMetricsServiceRequest,
5656
)
5757
from opentelemetry.proto.common.v1.common_pb2 import ( # noqa: F401
@@ -61,7 +61,7 @@
6161
KeyValue,
6262
KeyValueList,
6363
)
64-
from opentelemetry.proto.metrics.v1 import metrics_pb2 as pb2 # noqa: F401
64+
from opentelemetry.proto.metrics.v1 import metrics_pb2 as pb2
6565
from opentelemetry.proto.resource.v1.resource_pb2 import Resource # noqa: F401
6666
from opentelemetry.sdk.environment_variables import (
6767
_OTEL_PYTHON_EXPORTER_OTLP_HTTP_METRICS_CREDENTIAL_PROVIDER,
@@ -246,18 +246,19 @@ def _export(
246246

247247
def _export_with_retries(
248248
self,
249-
serialized_data: bytes,
249+
export_request: ExportMetricsServiceRequest,
250250
deadline_sec: float,
251251
) -> MetricExportResult:
252252
"""Export serialized data with retry logic until success, non-transient error, or exponential backoff maxed out.
253253
254254
Args:
255-
serialized_data: serialized metrics data to export
255+
export_request: ExportMetricsServiceRequest object containing metrics data to export
256256
deadline_sec: timestamp deadline for the export
257257
258258
Returns:
259259
MetricExportResult: SUCCESS if export succeeded, FAILURE otherwise
260260
"""
261+
serialized_data = export_request.SerializeToString()
261262
for retry_num in range(_MAX_RETRYS):
262263
# multiplying by a random number between .8 and 1.2 introduces a +/20% jitter to each backoff.
263264
backoff_seconds = 2**retry_num * random.uniform(0.8, 1.2)
@@ -313,23 +314,21 @@ def export(
313314
_logger.warning("Exporter already shutdown, ignoring batch")
314315
return MetricExportResult.FAILURE
315316

316-
serialized_data = encode_metrics(metrics_data)
317+
export_request = encode_metrics(metrics_data)
317318
deadline_sec = time() + self._timeout
318319

319320
# If no batch size configured, export as single batch with retries as configured
320321
if self._max_export_batch_size is None:
321-
return self._export_with_retries(
322-
serialized_data.SerializeToString(), deadline_sec
323-
)
322+
return self._export_with_retries(export_request, deadline_sec)
324323

325324
# Else, export in batches of configured size
326-
split_metrics_batches = list(
327-
_split_metrics_data(serialized_data, self._max_export_batch_size)
325+
batched_export_requests = _split_metrics_data(
326+
export_request, self._max_export_batch_size
328327
)
329328

330-
for split_metrics_data in split_metrics_batches:
329+
for split_metrics_data in batched_export_requests:
331330
export_result = self._export_with_retries(
332-
split_metrics_data.SerializeToString(),
331+
split_metrics_data,
333332
deadline_sec,
334333
)
335334
if export_result != MetricExportResult.SUCCESS:
@@ -356,18 +355,18 @@ def force_flush(self, timeout_millis: float = 10_000) -> bool:
356355

357356

358357
def _split_metrics_data(
359-
metrics_data: pb2.MetricsData,
358+
metrics_data: ExportMetricsServiceRequest,
360359
max_export_batch_size: int | None = None,
361-
) -> Iterable[pb2.MetricsData]:
362-
"""Splits metrics data into several MetricsData (copies protobuf originals),
360+
) -> Iterable[ExportMetricsServiceRequest]:
361+
"""Splits metrics data into several ExportMetricsServiceRequest (copies protobuf originals),
363362
based on configured data point max export batch size.
364363
365364
Args:
366365
metrics_data: metrics object based on HTTP protocol buffer definition
367366
368367
Returns:
369-
Iterable[pb2.MetricsData]: An iterable of pb2.MetricsData objects containing
370-
pb2.ResourceMetrics, pb2.ScopeMetrics, pb2.Metrics, and data points
368+
Iterable[ExportMetricsServiceRequest]: An iterable of ExportMetricsServiceRequest objects containing
369+
ExportMetricsServiceRequest.ResourceMetrics, ExportMetricsServiceRequest.ScopeMetrics, ExportMetricsServiceRequest.Metrics, and data points
371370
"""
372371
if not max_export_batch_size:
373372
return metrics_data
@@ -433,7 +432,7 @@ def _split_metrics_data(
433432
batch_size += 1
434433

435434
if batch_size >= max_export_batch_size:
436-
yield pb2.MetricsData(
435+
yield ExportMetricsServiceRequest(
437436
resource_metrics=_get_split_resource_metrics_pb2(
438437
split_resource_metrics
439438
)
@@ -447,6 +446,11 @@ def _split_metrics_data(
447446

448447
# Rebuild metric dict generically using same approach as initial creation
449448
field_name = metric.WhichOneof("data")
449+
if field_name is None:
450+
_logger.warning(
451+
"Tried to split and export an unsupported metric type. Skipping."
452+
)
453+
continue
450454
data_container = getattr(metric, field_name)
451455
metric_dict = {
452456
"name": metric.name,
@@ -494,7 +498,7 @@ def _split_metrics_data(
494498
split_resource_metrics.pop()
495499

496500
if batch_size > 0:
497-
yield pb2.MetricsData(
501+
yield ExportMetricsServiceRequest(
498502
resource_metrics=_get_split_resource_metrics_pb2(
499503
split_resource_metrics
500504
)
@@ -556,13 +560,13 @@ def _get_split_resource_metrics_pb2(
556560
new_resource_metrics = pb2.ResourceMetrics(
557561
resource=resource_metrics.get("resource"),
558562
scope_metrics=[],
559-
schema_url=resource_metrics.get("schema_url"),
563+
schema_url=resource_metrics.get("schema_url") or "",
560564
)
561565
for scope_metrics in resource_metrics.get("scope_metrics", []):
562566
new_scope_metrics = pb2.ScopeMetrics(
563567
scope=scope_metrics.get("scope"),
564568
metrics=[],
565-
schema_url=scope_metrics.get("schema_url"),
569+
schema_url=scope_metrics.get("schema_url") or "",
566570
)
567571

568572
for metric in scope_metrics.get("metrics", []):

0 commit comments

Comments
 (0)