Skip to content

Inferred Proxy Improvements #8782

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

Closed
wants to merge 34 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
934f400
add draft inferred proxy spans as http request parent
jordan-wong Feb 4, 2025
d0aa92b
revert accidental change to docs
jordan-wong Feb 4, 2025
25ec7b8
add draft http header parsing using Propagator design
jordan-wong Feb 13, 2025
6e6f67b
add BiConsumer logic for header visitor
jordan-wong Feb 14, 2025
a67d0da
merge master
jordan-wong Feb 19, 2025
7170583
merge master
jordan-wong Feb 25, 2025
bac390a
add misc fixes after merge master
jordan-wong Feb 25, 2025
4e5d8c7
add inferred proxy config
jordan-wong Feb 26, 2025
8216eb1
use inferred proxy config
jordan-wong Feb 26, 2025
0724360
add in progress debugging for header parsing
jordan-wong Feb 27, 2025
9938175
fix putting info in context object
jordan-wong Mar 4, 2025
ecee7d7
rename inferredProxySpan
jordan-wong Mar 4, 2025
6141896
remove unused InferredProxyCodec
jordan-wong Mar 4, 2025
3c74099
Merge branch 'master' into inferred-span-tags
jordan-wong Apr 8, 2025
c63ef4c
working version happy path using context
jordan-wong Apr 18, 2025
ddbc584
Merge branch 'master' into inferred-span-tags
zarirhamza Apr 24, 2025
9abec59
refactor code, remove debugging printlns
jordan-wong Apr 24, 2025
b004c19
fixed code
zarirhamza Apr 24, 2025
9016603
Merge branch 'master' into inferred-span-tags
zarirhamza Apr 25, 2025
77119c7
add tests for inferredProxySpans
jordan-wong Apr 28, 2025
c9882da
remove comments
jordan-wong Apr 28, 2025
1458e52
Merge branch 'master' into inferred-span-tags
zarirhamza Apr 28, 2025
bb26be8
Remove HttpServerDecorator.java.rej file
jordan-wong May 1, 2025
27cfb94
Update integrations-core submodule to latest master
jordan-wong May 1, 2025
ca4d546
Undo change to integrations-core submodule
jordan-wong May 1, 2025
d71753e
remove inferredProxyContext inject, remove stub isApiGatewaySupported…
jordan-wong May 5, 2025
dfcc717
Merge branch 'master' into inferred-span-tags
jordan-wong May 5, 2025
d9f55c5
fix env var reading
zarirhamza May 6, 2025
9c45d87
Merge branch 'master' into inferred-span-tags
zarirhamza May 6, 2025
9ed4910
add tests
zarirhamza May 6, 2025
d73cee5
fix context
zarirhamza May 6, 2025
ce06b40
Merge branch 'master' into inferred-span-tags
zarirhamza May 7, 2025
671772f
remove unused header parsing function
jordan-wong May 7, 2025
b94d809
add max capacity for InferredProxyContext hashmap for memory efficiency
jordan-wong May 7, 2025
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package datadog.context;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

public class InferredProxyContext implements ImplicitContextKeyed {
public static final ContextKey<InferredProxyContext> CONTEXT_KEY =
ContextKey.named("inferred-proxy-key");
private final Map<String, String> inferredProxy;

// at most 6 x-dd-proxy http headers to be extracted and stored into the Context hashmap,
// following API Gateway RFC
private final int DEFAULT_CAPACITY = 6;

public static InferredProxyContext fromContext(Context context) {
return context.get(CONTEXT_KEY);
}

public InferredProxyContext(Map<String, String> contextInfo) {
this.inferredProxy =
(contextInfo == null || contextInfo.isEmpty())
? new HashMap<>(DEFAULT_CAPACITY)
: new HashMap<>(contextInfo);
}

public InferredProxyContext() {
this.inferredProxy = new HashMap<>(DEFAULT_CAPACITY);
}

public Map<String, String> getInferredProxyContext() {
return Collections.unmodifiableMap(inferredProxy);
}

public void putInferredProxyInfo(String key, String value) {
inferredProxy.put(key, value);
}

public void removeInferredProxyInfo(String key) {
inferredProxy.remove(key);
}

/**
* Creates a new context with this value under its chosen key.
*
* @param context the context to copy the original values from.
* @return the new context with the implicitly keyed value.
* @see Context#with(ImplicitContextKeyed)
*/
@Override
public Context storeInto(Context context) {
return context.with(CONTEXT_KEY, this);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package datadog.context.propagation;

import datadog.context.Context;
import datadog.context.InferredProxyContext;
import java.util.function.BiConsumer;

public class InferredProxyPropagator implements Propagator {
public static final String INFERRED_PROXY_KEY = "x-dd-proxy";
/**
* METHOD STUB: InferredProxy is currently not meant to be injected to downstream services Injects
* a context into a downstream service using the given carrier.
*
* @param context the context containing the values to be injected.
* @param carrier the instance that will receive the key/value pairs to propagate.
* @param setter the callback to set key/value pairs into the carrier.
*/
@Override
public <C> void inject(Context context, C carrier, CarrierSetter<C> setter) {}

/**
* Extracts a context from un upstream service.
*
* @param context the base context to store the extracted values on top, use {@link
* Context#root()} for a default base context.
* @param carrier the instance to fetch the propagated key/value pairs from.
* @param visitor the callback to walk over the carrier and extract its key/value pais.
* @return A context with the extracted values on top of the given base context.
*/
@Override
public <C> Context extract(Context context, C carrier, CarrierVisitor<C> visitor) {
if (context == null || carrier == null || visitor == null) {
return context;
}
InferredProxyContextExtractor extractor = new InferredProxyContextExtractor();
visitor.forEachKeyValue(carrier, extractor);

InferredProxyContext extractedContext = extractor.extractedContext;
if (extractedContext == null) {
return context;
}
return extractedContext.storeInto(context);
}

public static class InferredProxyContextExtractor implements BiConsumer<String, String> {
private InferredProxyContext extractedContext;

InferredProxyContextExtractor() {}

/**
* Performs this operation on the given arguments.
*
* @param key the first input argument from an http header
* @param value the second input argument from an http header
*/
@Override
public void accept(String key, String value) {
if (key == null || key.isEmpty() || !key.startsWith(INFERRED_PROXY_KEY)) {
return;
}
if (extractedContext == null) {
extractedContext = new InferredProxyContext();
}
extractedContext.putInferredProxyInfo(key, value);
}
}
}
Loading