Skip to content

Instantly share code, notes, and snippets.

@kelunik
Created April 26, 2023 14:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kelunik/c3971068a7d1a1f0acd7c2143028ce1b to your computer and use it in GitHub Desktop.
Save kelunik/c3971068a7d1a1f0acd7c2143028ce1b to your computer and use it in GitHub Desktop.
Elastic APM
public class PlatformContextProvider implements ContextDataProvider {
private static final Map<String, String> CONTEXT = new ConcurrentHashMap<>();
static {
CONTEXT.put("service.version", ...);
CONTEXT.put("service.environment", ...);
}
@Override
public Map<String, String> supplyContextData() {
Map<String, String> map = new HashMap<>(CONTEXT);
String traceId = ElasticApm.currentTransaction().getTraceId();
if ( !traceId.isEmpty() ) {
map.put("trace.id", traceId);
}
String transactionId = ElasticApm.currentTransaction().getId();
if ( !transactionId.isEmpty() ) {
map.put("transaction.id", transactionId);
}
return map;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment