[Bug]: OTel ignores the invocation-local X-Ray header on Lambda Managed Instances
Les mainteneurs répondent en général sous 1 jour
Personne n'a encore pris cette issue.
Évaluation
- Difficulté
- 5/5
- Temps estimé
- Plus d'une semaine
- Accessibilité débutants
- 38/100
- Type d'issue
- Bug
- Clarté
- Clairement spécifiée
- Activité
- Active
- Stack technique
- aws, java
- Domaine
- backend, observability-sre
Piste de recherche
Start with otel-plugin/src/main/java/software/amazon/lambda/durable/otel/XRayContextExtractor.java, sdk/src/main/java/software/amazon/lambda/durable/plugin/InvocationInfo.java, and the invocation/plugin entry points; run the supplied LmiTraceCarrierProbe first. Trace how invocation data reaches worker threads, then verify preserved Root, Parent, and sampling values for overlapping, replay, and resume cases while retaining ordinary-Lambda behavior and adding deployed LMI validation.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
Expected Behavior
The Java OTel integration should preserve the trace ID, parent and sampling decision provided by the LMI invocation context. This information must remain scoped to the invocation, including when the SDK dispatches user code to another thread.
Actual Behavior
Java LMI supplies Context.getXrayTraceId() and puts the header in the runtime ThreadLocal carrier. It does not update the ordinary Lambda global system property. The default XRayContextExtractor reads only com.amazonaws.xray.traceHeader, then _X_AMZN_TRACE_ID; neither path reaches the LMI header.
With a valid Sampled=0 header placed in both an invocation Context and the runtime-style SdkInternalThreadLocal carrier, the published extractor returns null. Both OTel views then export sampled Invocation/Workflow on a different trace when the fallback sampler is AlwaysOn. The ordinary-Lambda system-property control correctly extracts NOT_SAMPLED and exports no spans.
Steps to Reproduce
Use software.amazon.lambda.durable:aws-durable-execution-sdk-java-plugin-otel:2.2.1 and io.opentelemetry:opentelemetry-sdk-testing:1.65.0 with their transitive dependencies in a scratch Maven project. Run LmiTraceCarrierProbe below with _X_AMZN_TRACE_ID unset. The probe uses the real published plugins/exporter and the same ThreadLocal key used by the runtime; it makes no AWS calls.
The Context/ThreadLocal fixture models LMI input. It does not start a real Lambda runtime. Both the missing-header observation and the ordinary-carrier control are asserted.
Reproduction code
import java.lang.reflect.Proxy;
import java.time.Instant;
import java.util.*;
import com.amazonaws.services.lambda.runtime.Context;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.opentelemetry.sdk.trace.SdkTracerProvider;
import io.opentelemetry.sdk.trace.samplers.Sampler;
import io.opentelemetry.sdk.trace.export.SimpleSpanProcessor;
import io.opentelemetry.sdk.testing.exporter.InMemorySpanExporter;
import software.amazon.awssdk.utilslite.SdkInternalThreadLocal;
import software.amazon.lambda.durable.otel.*;
import software.amazon.lambda.durable.plugin.*;
public class LmiTraceCarrierProbe {
static final String HEADER = "Root=1-6955b900-123456789012345678901234;Parent=1234567890123456;Sampled=0";
static final String EXPECTED_TRACE = "6955b900123456789012345678901234";
static final String PROPERTY = "com.amazonaws.xray.traceHeader";
static final String KEY = "AWS_LAMBDA_X_TRACE_ID";
public static void main(String[] args) throws Exception {
if (System.getenv("_X_AMZN_TRACE_ID") != null) throw new AssertionError("Probe requires no environment header");
Context runtimeContext = (Context) Proxy.newProxyInstance(Context.class.getClassLoader(), new Class<?>[]{Context.class},
(proxy, method, values) -> {
if (method.getName().equals("getXrayTraceId")) return HEADER;
throw new UnsupportedOperationException(method.getName());
});
var results = new ArrayList<Map<String,Object>>();
for (boolean ordinary : new boolean[]{false,true}) {
System.clearProperty(PROPERTY);
SdkInternalThreadLocal.remove(KEY);
if (ordinary) System.setProperty(PROPERTY, HEADER);
else SdkInternalThreadLocal.put(KEY, HEADER);
var extracted = new XRayContextExtractor().extract();
if (ordinary && (extracted == null || !EXPECTED_TRACE.equals(extracted.traceId()) || extracted.sampling() != ExtractedContext.Sampling.NOT_SAMPLED))
throw new AssertionError("Ordinary carrier failed");
if (!ordinary && (extracted != null || !HEADER.equals(runtimeContext.getXrayTraceId()) || !HEADER.equals(SdkInternalThreadLocal.get(KEY))))
throw new AssertionError("LMI fixture or expected extractor result differs");
for (boolean executionView : new boolean[]{true,false}) {
var exporter = InMemorySpanExporter.create();
var builder = SdkTracerProvider.builder().setSampler(Sampler.alwaysOn())
.addSpanProcessor(SimpleSpanProcessor.create(exporter));
var config = OtelPluginConfig.builder().enableMdc(false).build();
DurableExecutionPlugin plugin = executionView ? new ExecutionOtelPlugin(builder,config) : new InvocationOtelPlugin(builder,config);
var arn="arn:aws:lambda:us-west-2:123456789012:function:probe:1/durable-execution/probe/id";
plugin.onInvocationStart(new InvocationInfo("request",arn,true,Instant.parse("2026-10-02T00:00:00Z")));
plugin.onInvocationEnd(new InvocationEndInfo("request",arn,true,InvocationStatus.SUCCEEDED,null));
var spans = exporter.getFinishedSpanItems().stream().map(s -> Map.of(
"name",s.getName(),"traceId",s.getTraceId(),"sampled",s.getSpanContext().isSampled())).toList();
if (ordinary && !spans.isEmpty()) throw new AssertionError("Upstream Sampled=0 must suppress exports");
if (!ordinary && (spans.size()!=2 || exporter.getFinishedSpanItems().stream().anyMatch(s -> EXPECTED_TRACE.equals(s.getTraceId()) || !s.getSpanContext().isSampled())))
throw new AssertionError("Unexpected LMI-path observation");
var record = new LinkedHashMap<String,Object>();
record.put("carrier",ordinary?"ordinary Lambda system property":"LMI context plus runtime ThreadLocal");
record.put("plugin",plugin.getClass().getSimpleName());
record.put("inputSampling","NOT_SAMPLED");
record.put("extractor",extracted==null?null:Map.of("traceId",extracted.traceId(),"sampling",extracted.sampling().name()));
record.put("spans",spans);
results.add(record);
}
}
System.clearProperty(PROPERTY);
SdkInternalThreadLocal.remove(KEY);
System.out.println(new ObjectMapper().writeValueAsString(Map.of("sdkAndPluginVersion","2.2.1","results",results,"checksPassed",true)));
}
}
SDK Version
Core SDK / OTel plugin 2.2.1. Main rechecked at 78574e3051aac9b5ca00a0c1fd2b91eab72a9e15.
Java Version
Corretto 25.0.4.1
Is this a regression?
Unknown; no last-known-good version has been established.
Additional Context
Sources: Java LMI request-context contract, runtime carrier selection, default extractor, and plugin invocation information.
PR #721, checked at c7be25f4a441a9629a8337b22f577d3abf25640c, leaves the extractor unchanged. This is separate from shared plugin-state isolation. Python is not affected by this carrier change: its official LMI runtime continues to support the environment header.
Acceptance criteria
- Capture the header from the Lambda Context and pass it through invocation-local SDK/plugin data, accounting for worker-thread dispatch.
- Preserve Root, Parent and explicit sampling; retain ordinary Lambda compatibility and deterministic fallback for genuinely absent/invalid headers.
- Avoid global system-property/environment writes and test overlapping invocations with distinct headers plus replay/resume.
- Add deployed LMI validation; the observations here are local reproductions and source inspection.
Related cross-SDK tracking: https://github.com/aws/aws-durable-execution-sdk-js/issues/951
- Langage dominant
- Java
- Étoiles
- 28
- Forks
- 16
- Merge moyen
- 2 j 3 h
- PR mergées (30 j)
- 62
Préparer son environnement
- Aucun Dockerfile ni fichier Docker Compose
- Propose un modèle de pull request
- Lire le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de aws/aws-durable-execution-sdk-java
-
documentation needs-triage
Difficulté 1/5 1-3 heures Accessibilité débutants 88/100
aws/aws-durable-execution-sdk-java#843 ·
Les mainteneurs répondent en général sous 1 jour
-
documentation pkg:sdk
Difficulté 1/5 1-3 heures Accessibilité débutants 88/100
aws/aws-durable-execution-sdk-java#645 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour
-
enhancement
Difficulté 2/5 1-3 heures Accessibilité débutants 68/100
aws/aws-durable-execution-sdk-java#300 ·
Les mainteneurs répondent en général sous 1 jour
-
[Feature]: Add invocation-owned executor isolationPeut-être pris @zhongkechen l’a pris il y a 34 jours. Ouverteenhancement pkg:sdk
Difficulté 5/5 Plus d'une semaine Accessibilité débutants 1/100
aws/aws-durable-execution-sdk-java#840 ·
Les mainteneurs répondent en général sous 1 jour
-
bug pkg:sdk
Difficulté 5/5 Plus d'une semaine Accessibilité débutants 25/100
aws/aws-durable-execution-sdk-java#839 ·
Les mainteneurs répondent en général sous 1 jour
Toutes les issues de aws/aws-durable-execution-sdk-java
Issues similaires
-
Component: Frontend Component: Web Component Type: Maintenance
Difficulté 2/5 1-3 heures Accessibilité débutants 76/100
it-at-m/refarch-templates#1944 ·
Les mainteneurs répondent en général sous 2 jours
-
priority: p2 type: bug
Difficulté 2/5 1-3 heures Accessibilité débutants 68/100
googleapis/java-genai#1372 ·
Les mainteneurs répondent en général sous 1 jour
-
Difficulté 2/5 1-3 heures Accessibilité débutants 60/100
-
GeoSeries scale and skew tests fail with pytest 9.2.0Peut-être pris @jiayuasu l’a pris aujourd’hui. Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 82/100
Les mainteneurs répondent en général sous 1 jour
-
Preventions: a dose saved without a unit reopens blank, and an unchanged save then erases itOuvertepriority: medium Review effort [1-5]: 3 status: needs-triage type: bug
Difficulté 2/5 1-3 heures Accessibilité débutants 78/100
carlos-emr/carlos#5431 ·
Les mainteneurs répondent en général sous 1 jour