Repository navigation
fix(otel): export sampled fallback roots early #754
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
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
aae44c4
fix(otel): export sampled fallback roots early
3048aff
test(otel): verify fallback on installed core
325a0c9
fix(otel): consume root trace ID before callbacks
ff4d6ab
fix(otel): preserve public ID override scopes
0c74059
Merge branch 'main' into fix/otel-fallback-root
zhongkechen 9e4265c
Merge commit 'refs/maintenance-python-20261006/base' into maintenance…
d7eb42c
Merge commit 'refs/maintenance-python-20261006/base' into maintenance…
35d02c6
ci: route OTel conformance to CodeBuild
d657284
ci: preserve queued conformance runs
ffb1251
ci: adopt shared backend queue preservation
1a57d1d
fix: build new js example workspace dependencies
dc429fd
fix: preserve synthetic root attributes
15caff4
chore: merge main after telemetry view guard
2492e71
ci: pin published conformance workflow
a4fe1a9
chore: merge invocation worker lifecycle
6d6edb2
chore: merge microvm worker base update
e3c2d41
fix(otel): stabilize anchors and sampling intent
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
...ble-execution-sdk-python-otel/src/aws_durable_execution_sdk_python_otel/execution_root.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| """Materialize the stable SDK-owned ancestor of a fallback execution trace.""" | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| from dataclasses import dataclass | ||
| from datetime import datetime | ||
|
|
||
| from opentelemetry.context import Context | ||
| from opentelemetry.sdk.trace.sampling import SamplingResult | ||
| from opentelemetry.trace import SpanContext, SpanKind, Tracer | ||
|
|
||
| from aws_durable_execution_sdk_python_otel.deterministic_id_generator import ( | ||
| DeterministicIdGenerator, | ||
| ) | ||
| from aws_durable_execution_sdk_python_otel.durable_sampling import ( | ||
| DurableSamplingIntent, | ||
| store_sampling_intent, | ||
| ) | ||
| from aws_durable_execution_sdk_python_otel.timestamps import to_otel_timestamp | ||
|
|
||
|
|
||
| @dataclass(frozen=True) | ||
| class ExecutionRoot: | ||
| """A zero-duration anchor, reproducible in any invocation of an execution. | ||
|
|
||
| Re-exporting the same anchor permits recovery after a failed flush without | ||
| checkpointing telemetry state. The anchor carries stable SDK attributes; | ||
| configured provider resources and processor enrichment remain unchanged. | ||
| """ | ||
|
|
||
| execution_arn: str | ||
| ancestor: SpanContext | ||
| start_time: datetime | ||
|
|
||
| def export( | ||
| self, | ||
| tracer: Tracer, | ||
| id_generator: DeterministicIdGenerator, | ||
| sampling_intent: DurableSamplingIntent, | ||
| ) -> None: | ||
| """Export a sampled local ancestor; never replace an external parent.""" | ||
| if self.ancestor.is_remote or not self.ancestor.trace_flags.sampled: | ||
|
zhongkechen marked this conversation as resolved.
zhongkechen marked this conversation as resolved.
|
||
| return | ||
|
zhongkechen marked this conversation as resolved.
|
||
|
|
||
| # Reuse only the resolved decision without resampling. This same-ID | ||
| # anchor must not acquire variable sampler attributes or tracestate. | ||
| # The regular tracer preserves configured resources and processors. | ||
| root_attributes: dict[str, str | bool] = { | ||
| "durable.execution.arn": self.execution_arn, | ||
| "durable.execution.synthetic_root": True, | ||
| } | ||
| root_intent = DurableSamplingIntent( | ||
| SamplingResult(sampling_intent.result.decision) | ||
| ) | ||
| root_context = store_sampling_intent(Context(), root_intent) | ||
| timestamp = to_otel_timestamp(self.start_time) | ||
| with id_generator._use_ids_for_span( | ||
| trace_id=self.ancestor.trace_id, | ||
| span_id=self.ancestor.span_id, | ||
| ): | ||
| span = tracer.start_span( | ||
| "DurableExecutionRoot", | ||
| context=root_context, | ||
| kind=SpanKind.INTERNAL, | ||
| attributes=root_attributes, | ||
| start_time=timestamp, | ||
| ) | ||
| span.end(end_time=timestamp) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
...durable-execution-sdk-python-otel/src/aws_durable_execution_sdk_python_otel/timestamps.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| """OpenTelemetry timestamp conversion shared by span producers.""" | ||
|
|
||
| from datetime import datetime | ||
|
|
||
|
|
||
| def to_otel_timestamp(value: datetime) -> int: | ||
| """Convert a datetime to nanoseconds using the SDK's existing precision.""" | ||
| return int(value.timestamp() * 1_000_000_000) |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.