|
44 | 44 | EventTypes, |
45 | 45 | EventSubtypes, |
46 | 46 | ) |
| 47 | +from datadog_lambda.durable import extract_context_from_durable_execution |
47 | 48 |
|
48 | 49 | if config.otel_enabled: |
49 | 50 | from opentelemetry.trace import set_tracer_provider |
|
61 | 62 | DD_TRACE_JAVA_TRACE_ID_PADDING = "00000000" |
62 | 63 | HIGHER_64_BITS = "HIGHER_64_BITS" |
63 | 64 | LOWER_64_BITS = "LOWER_64_BITS" |
64 | | -_TRACE_CHECKPOINT_PREFIX = "_datadog_" |
65 | 65 |
|
66 | 66 |
|
67 | 67 | def _dsm_set_checkpoint(context_json, event_type, arn): |
@@ -547,60 +547,6 @@ def extract_context_from_step_functions(event, lambda_context): |
547 | 547 | return extract_context_from_lambda_context(lambda_context) |
548 | 548 |
|
549 | 549 |
|
550 | | -def _extract_context_from_durable_checkpoint(operation): |
551 | | - # Checkpoint data is written by the dd-trace-py in Datadog style |
552 | | - # (x-datadog-* headers). Extraction goes through the standard |
553 | | - # propagator.extract path, which honors DD_TRACE_PROPAGATION_STYLE_EXTRACT. |
554 | | - # The default extract list (datadog, tracecontext, baggage) already |
555 | | - # includes datadog. Customers who override the extract list MUST keep |
556 | | - # datadog in it. |
557 | | - if not isinstance(operation, dict): |
558 | | - return None |
559 | | - |
560 | | - step_details = operation.get("StepDetails") |
561 | | - if not isinstance(step_details, dict): |
562 | | - return None |
563 | | - |
564 | | - result = step_details.get("Result") |
565 | | - if isinstance(result, str): |
566 | | - try: |
567 | | - result = json.loads(result) |
568 | | - except Exception: |
569 | | - return None |
570 | | - |
571 | | - if not isinstance(result, dict): |
572 | | - return None |
573 | | - |
574 | | - return propagator.extract(result) |
575 | | - |
576 | | - |
577 | | -def extract_context_from_durable_execution(event): |
578 | | - operations = event.get("InitialExecutionState", {}).get("Operations") |
579 | | - if isinstance(operations, dict): |
580 | | - operations = list(operations.values()) |
581 | | - if not isinstance(operations, list) or not operations: |
582 | | - return None |
583 | | - |
584 | | - highest = -1 |
585 | | - best_operation = None |
586 | | - for operation in operations: |
587 | | - if not isinstance(operation, dict): |
588 | | - continue |
589 | | - name = operation.get("Name") |
590 | | - if not isinstance(name, str) or not name.startswith(_TRACE_CHECKPOINT_PREFIX): |
591 | | - continue |
592 | | - suffix = name[len(_TRACE_CHECKPOINT_PREFIX) :] |
593 | | - try: |
594 | | - number = int(suffix) |
595 | | - except (TypeError, ValueError): |
596 | | - continue |
597 | | - if number > highest: |
598 | | - highest = number |
599 | | - best_operation = operation |
600 | | - |
601 | | - return _extract_context_from_durable_checkpoint(best_operation) |
602 | | - |
603 | | - |
604 | 550 | def extract_context_custom_extractor(extractor, event, lambda_context): |
605 | 551 | """ |
606 | 552 | Extract Datadog trace context using a custom trace extractor function |
|
0 commit comments