Created
April 26, 2023 14:11
-
-
Save kelunik/c3971068a7d1a1f0acd7c2143028ce1b to your computer and use it in GitHub Desktop.
Elastic APM
This file contains 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
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