Description
Custom IDs would allow for users to set IDs that they need right at the beginning of a span. This is important if the downstream services or eventual backend that receives these spans need them to be in a certain format. The opentelemtry-java SDK and opentelemetry-js SDK do this as well.
Is your feature request related to a problem?
Yes, some backends depend on the trace being in a certain format. Failure to be in the correct format can mean the trace is rejected and unusable with some backends.
For example, the AWS X-Ray service depends on the the trace id format being in a certain format.
If the trace-id is not valid (because the backend parses the id and decides the trace was sent more than 30 min ago) the trace is rejected.
Describe the solution you'd like
Like the SDKs mentioned above, it would be helpful to define a IdsGenerator
interface from which all Id Generators Classes will conform to and provide the generate_trace_id()
and generate_span_id()
functions.
This will replace the same functions in the root of the opentelemetry.sdk.trace
directory at opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py
This way users can specify the IdsGenerator they want in the TracerProvider config (e.g. TracerProvider(ids_generator=AWSXRayIdsGenerator())
. Otherwise by default, the RandomIdsGenerator()
will be used.
Describe alternatives you've considered
- Backend Services like XRay could just replace the ID and create a new one later in the chain (at the collector?) but this would possibly be too late because the trace can be propagated to other services...
Additional context
The main ideas behind this change are:
- Define a
IdsGenerator
interface - Define a default
RandomIdsGenerator()
class which implementsIdsGenerator
and is used byTracerProvider
- Allow users to provide their own
IdsGenerator
in the config ofTracerProvider
- Updates tests which use the exposed
generate_trace_id()
andgenerate_span_id()
functions.
I started a DRAFT PR here