Skip to content

Switch gRPC exporters to use official gRPC retry config. Make timeout encompass retries/backoffs #4564

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- typecheck: add sdk/resources and drop mypy
([#4578](https://github.com/open-telemetry/opentelemetry-python/pull/4578))
- Refactor `BatchLogRecordProcessor` to simplify code and make the control flow more
clear ([#4562](https://github.com/open-telemetry/opentelemetry-python/pull/4562/)
and [#4535](https://github.com/open-telemetry/opentelemetry-python/pull/4535)).
- Update OTLP gRPC/HTTP exporters: the export timeout is now inclusive of all retries and backoffs,
and an unnecessary 32 second sleep that occurred after all retries had completed/failed was removed.
Update gRPC OTLP Exporters to use official gRPC retry policy config. The `RetryInfo` proto in the error
response will now be ignored, and server's should now use the gRPC supported header `grpc-retry-pushback-ms`.
([#4564](https://github.com/open-telemetry/opentelemetry-python/pull/4564)).
- Use PEP702 for marking deprecations
([#4522](https://github.com/open-telemetry/opentelemetry-python/pull/4522))
- Refactor `BatchLogRecordProcessor` and `BatchSpanProcessor` to simplify code
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ classifiers = [
]
dependencies = [
"opentelemetry-proto == 1.34.0.dev",
"requests ~= 2.7",
]

[project.urls]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,18 @@

import logging
from collections.abc import Sequence
from itertools import count
from typing import (
Any,
Callable,
Dict,
Iterator,
List,
Mapping,
Optional,
TypeVar,
)

import requests

from opentelemetry.proto.common.v1.common_pb2 import AnyValue as PB2AnyValue
from opentelemetry.proto.common.v1.common_pb2 import (
ArrayValue as PB2ArrayValue,
Expand Down Expand Up @@ -110,6 +110,14 @@ def _encode_key_value(
)


def _is_retryable(resp: requests.Response) -> bool:
if resp.status_code == 408:
return True
if resp.status_code >= 500 and resp.status_code <= 599:
return True
return False


def _encode_array(
array: Sequence[Any], allow_null: bool = False
) -> Sequence[PB2AnyValue]:
Expand Down Expand Up @@ -177,38 +185,3 @@ def _get_resource_data(
)
)
return resource_data


def _create_exp_backoff_generator(max_value: int = 0) -> Iterator[int]:
"""
Generates an infinite sequence of exponential backoff values. The sequence starts
from 1 (2^0) and doubles each time (2^1, 2^2, 2^3, ...). If a max_value is specified
and non-zero, the generated values will not exceed this maximum, capping at max_value
instead of growing indefinitely.

Parameters:
- max_value (int, optional): The maximum value to yield. If 0 or not provided, the
sequence grows without bound.

Returns:
Iterator[int]: An iterator that yields the exponential backoff values, either uncapped or
capped at max_value.

Example:
```
gen = _create_exp_backoff_generator(max_value=10)
for _ in range(5):
print(next(gen))
```
This will print:
1
2
4
8
10

Note: this functionality used to be handled by the 'backoff' package.
"""
for i in count(0):
out = 2**i
yield min(out, max_value) if max_value else out
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
asgiref==3.7.2
importlib-metadata==6.11.0
iniconfig==2.0.0
requests == 2.7.0
packaging==24.0
pluggy==1.5.0
protobuf==5.26.1
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def __init__(
headers: Optional[
Union[TypingSequence[Tuple[str, str]], Dict[str, str], str]
] = None,
timeout: Optional[int] = None,
timeout: Optional[float] = None,
compression: Optional[Compression] = None,
):
if insecure is None:
Expand All @@ -79,7 +79,7 @@ def __init__(

environ_timeout = environ.get(OTEL_EXPORTER_OTLP_LOGS_TIMEOUT)
environ_timeout = (
int(environ_timeout) if environ_timeout is not None else None
float(environ_timeout) if environ_timeout is not None else None
)

compression = (
Expand Down
Loading
Loading