78
Tracing for Java Developers Philipp Krenn@xeraa @xeraa

Tracing - xeraa.org · Metrics SLI, SLA, SLO Four golden signals: latency, traffic, errors, saturation 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4@xeraa

  • Upload
    others

  • View
    10

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Tracing - xeraa.org · Metrics SLI, SLA, SLO Four golden signals: latency, traffic, errors, saturation 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4@xeraa

Tracingfor Java DevelopersPhilipp Krenn@xeraa

@xeraa

Page 2: Tracing - xeraa.org · Metrics SLI, SLA, SLO Four golden signals: latency, traffic, errors, saturation 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4@xeraa

Developer !

@xeraa

Page 3: Tracing - xeraa.org · Metrics SLI, SLA, SLO Four golden signals: latency, traffic, errors, saturation 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4@xeraa
Page 4: Tracing - xeraa.org · Metrics SLI, SLA, SLO Four golden signals: latency, traffic, errors, saturation 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4@xeraa

LogsUsed by everyone?

@xeraa

Page 5: Tracing - xeraa.org · Metrics SLI, SLA, SLO Four golden signals: latency, traffic, errors, saturation 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4@xeraa
Page 6: Tracing - xeraa.org · Metrics SLI, SLA, SLO Four golden signals: latency, traffic, errors, saturation 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4@xeraa
Page 7: Tracing - xeraa.org · Metrics SLI, SLA, SLO Four golden signals: latency, traffic, errors, saturation 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4@xeraa

Logs !

EventsStructure & context

@xeraa

Page 8: Tracing - xeraa.org · Metrics SLI, SLA, SLO Four golden signals: latency, traffic, errors, saturation 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4@xeraa

{ "@timestamp": "2019-11-20T16:53:01.746Z", "log.level": "INFO", "message": "[philipp] failed to log in with password [***]", "service.name": "gs-securing-web", "process.thread.name": "http-nio-8080-exec-8", "log.logger": "hello.AuthenticationEventListener", "labels.event.category": "LOGIN_FAILURE", "labels.user.name": "philipp", "labels.source.ip": "0:0:0:0:0:0:0:1", "labels.url.full": "/login"}

@xeraa

Page 9: Tracing - xeraa.org · Metrics SLI, SLA, SLO Four golden signals: latency, traffic, errors, saturation 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4@xeraa

MetricsUsed by most?

@xeraa

Page 10: Tracing - xeraa.org · Metrics SLI, SLA, SLO Four golden signals: latency, traffic, errors, saturation 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4@xeraa
Page 11: Tracing - xeraa.org · Metrics SLI, SLA, SLO Four golden signals: latency, traffic, errors, saturation 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4@xeraa
Page 12: Tracing - xeraa.org · Metrics SLI, SLA, SLO Four golden signals: latency, traffic, errors, saturation 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4@xeraa

MetricsSLI, SLA, SLO

Four golden signals:latency, traffic, errors,

saturation

@xeraa

Page 13: Tracing - xeraa.org · Metrics SLI, SLA, SLO Four golden signals: latency, traffic, errors, saturation 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4@xeraa

UptimeUsed by many?

@xeraa

Page 14: Tracing - xeraa.org · Metrics SLI, SLA, SLO Four golden signals: latency, traffic, errors, saturation 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4@xeraa
Page 15: Tracing - xeraa.org · Metrics SLI, SLA, SLO Four golden signals: latency, traffic, errors, saturation 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4@xeraa
Page 16: Tracing - xeraa.org · Metrics SLI, SLA, SLO Four golden signals: latency, traffic, errors, saturation 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4@xeraa

UptimeSynthetic / (pro)active

monitoring

@xeraa

Page 17: Tracing - xeraa.org · Metrics SLI, SLA, SLO Four golden signals: latency, traffic, errors, saturation 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4@xeraa

TracesUsed by some?

@xeraa

Page 18: Tracing - xeraa.org · Metrics SLI, SLA, SLO Four golden signals: latency, traffic, errors, saturation 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4@xeraa
Page 19: Tracing - xeraa.org · Metrics SLI, SLA, SLO Four golden signals: latency, traffic, errors, saturation 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4@xeraa
Page 20: Tracing - xeraa.org · Metrics SLI, SLA, SLO Four golden signals: latency, traffic, errors, saturation 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4@xeraa

TracesApplication Performance

MonitoringDistributed Tracing

@xeraa

Page 21: Tracing - xeraa.org · Metrics SLI, SLA, SLO Four golden signals: latency, traffic, errors, saturation 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4@xeraa

...the monitoring and management of performance

and availability of software applications.

— Wikipedia

@xeraa

Page 22: Tracing - xeraa.org · Metrics SLI, SLA, SLO Four golden signals: latency, traffic, errors, saturation 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4@xeraa

Simpler Times

https://www.kartar.net/2019/07/intro-to-distributed-tracing/

@xeraa

Page 23: Tracing - xeraa.org · Metrics SLI, SLA, SLO Four golden signals: latency, traffic, errors, saturation 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4@xeraa

Better Times for Vendors

https://www.kartar.net/2019/07/intro-to-distributed-tracing/

@xeraa

Page 24: Tracing - xeraa.org · Metrics SLI, SLA, SLO Four golden signals: latency, traffic, errors, saturation 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4@xeraa

GoalsTransaction context

Reconstruct flowQuery & visualize transcations

@xeraa

Page 25: Tracing - xeraa.org · Metrics SLI, SLA, SLO Four golden signals: latency, traffic, errors, saturation 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4@xeraa

AgentsLanguage & framework specificDetect start & end of request,

capture errors

@xeraa

Page 26: Tracing - xeraa.org · Metrics SLI, SLA, SLO Four golden signals: latency, traffic, errors, saturation 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4@xeraa

AgentsWrap operations in standard &

known 3rd party librariesExtract additional information

@xeraa

Page 27: Tracing - xeraa.org · Metrics SLI, SLA, SLO Four golden signals: latency, traffic, errors, saturation 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4@xeraa

AgentsLittle to no overhead

Trace & hook, not profile

@xeraa

Page 28: Tracing - xeraa.org · Metrics SLI, SLA, SLO Four golden signals: latency, traffic, errors, saturation 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4@xeraa

AgentsLive in / attach to app process

public static void mainpremain

agentmain

https://www.javaadvent.com/2019/12/a-beginners-guide-to-java-agents.html

@xeraa

Page 29: Tracing - xeraa.org · Metrics SLI, SLA, SLO Four golden signals: latency, traffic, errors, saturation 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4@xeraa

premain

package sample;public class SimpleAgent<?> { public static void premain(String argument) { System.out.println("Hello " + argument); }}

Premain-Class: sample.SimpleAgent

java -javaagent:/opt/agent.jar=World some.Program

@xeraa

Page 30: Tracing - xeraa.org · Metrics SLI, SLA, SLO Four golden signals: latency, traffic, errors, saturation 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4@xeraa

Instrumentation API

package sample;public class ClassLoadingAgent { public static void premain(String argument, Instrumentation instrumentation) { instrumentation.addTransformer(new ClassFileTransformer() { @Override public byte[] transform(Module module, ClassLoader loader, String name, Class<?> typeIfLoaded, ProtectionDomain domain, byte[] bu!er) { System.out.println("Class was loaded: " + name); return null; } }); }}

@xeraa

Page 31: Tracing - xeraa.org · Metrics SLI, SLA, SLO Four golden signals: latency, traffic, errors, saturation 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4@xeraa

ByteBuddy

package sample;public class ByteBuddySampleAgent { public static void premain(String argument, Instrumentation instrumentation) { new AgentBuilder.Default() .type(ElementMatchers.any()) .transform((DynamicType.Builder<?> builder, TypeDescription type, ClassLoader loader, JavaModule module) -> { System.out.println("Class was loaded: " + name); return builder; }).installOn(instrumentation); }}

@xeraa

Page 32: Tracing - xeraa.org · Metrics SLI, SLA, SLO Four golden signals: latency, traffic, errors, saturation 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4@xeraa

Measuring Time

public class TimeMeasurementAdvice { @Advice.OnMethodEnter public static long enter() { return System.currentTimeMillis(); } @Advice.OnMethodExit(onThrowable = Throwable.class) public static void exit(@Advice.Enter long start, @Advice.Origin String origin) { long executionTime = System.currentTimeMillis() - start; System.out.println(origin + " took " + executionTime + " to execute"); }}

@xeraa

Page 33: Tracing - xeraa.org · Metrics SLI, SLA, SLO Four golden signals: latency, traffic, errors, saturation 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4@xeraa

Measure Time through ByteBuddy

package sample;public class ByteBuddyTimeMeasuringAgent { public static void premain(String argument, Instrumentation instrumentation) { Advice advice = Advice.to(TimeMeasurementAdvice.class); new AgentBuilder.Default() .type(ElementMatchers.isAnnotatedBy(MeasureTime.class)) .transform((DynamicType.Builder<?> builder, TypeDescription type, ClassLoader loader, JavaModule module) -> { return builder.visit(advice.on(ElementMatchers.isMethod()); }).installOn(instrumentation); }}

@xeraa

Page 34: Tracing - xeraa.org · Metrics SLI, SLA, SLO Four golden signals: latency, traffic, errors, saturation 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4@xeraa

Tracing

https://opentracing.io/docs/overview/@xeraa

Page 35: Tracing - xeraa.org · Metrics SLI, SLA, SLO Four golden signals: latency, traffic, errors, saturation 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4@xeraa

OpenTracingPromises vendor-neutral APIs

for tracingScheduled for sunsetting

@xeraa

Page 36: Tracing - xeraa.org · Metrics SLI, SLA, SLO Four golden signals: latency, traffic, errors, saturation 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4@xeraa

Distributed TracingTrace ID propagation

traceparent:00- // Version0af7651916cd43dd8448eb211c80319c- // Trace IDb7ad6b7169203331- // Parent span ID01 // Flags (sampling)

@xeraa

Page 37: Tracing - xeraa.org · Metrics SLI, SLA, SLO Four golden signals: latency, traffic, errors, saturation 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4@xeraa

OpenTelemetrySupersedes OpenTracing +

OpenCensusBackwards compatible with

both where possible

@xeraa

Page 38: Tracing - xeraa.org · Metrics SLI, SLA, SLO Four golden signals: latency, traffic, errors, saturation 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4@xeraa

OpenTelemetryPluggable collector process

exporter instead of rebuilding your app

@xeraa

Page 39: Tracing - xeraa.org · Metrics SLI, SLA, SLO Four golden signals: latency, traffic, errors, saturation 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4@xeraa

OpenTracing marketed itself as a standard from the onset, never even released a 1.0 version of its java impl before canceling the project. OpenCensus also never made 1.0 in its years before canceling itself.

OpenTelemetery has in all its time produced a single 0.2 release

— https://twitter.com/adrianfcole/status/1223778238469566464

@xeraa

Page 40: Tracing - xeraa.org · Metrics SLI, SLA, SLO Four golden signals: latency, traffic, errors, saturation 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4@xeraa

SamplingRepresentative subset

Random or "interesting" traces

@xeraa

Page 41: Tracing - xeraa.org · Metrics SLI, SLA, SLO Four golden signals: latency, traffic, errors, saturation 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4@xeraa

Elastic's Current Sampling StrategySingle service: Head-based /

randomDistributed: First service

chooses@xeraa

Page 42: Tracing - xeraa.org · Metrics SLI, SLA, SLO Four golden signals: latency, traffic, errors, saturation 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4@xeraa

APM ServerSeparate process for receiving

traces from agentsTransforms and enriches data

@xeraa

Page 43: Tracing - xeraa.org · Metrics SLI, SLA, SLO Four golden signals: latency, traffic, errors, saturation 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4@xeraa

Elastic's APM ServerWritten in Go, using the Beats

frameworkOptional authentication & rate

limiting

@xeraa

Page 44: Tracing - xeraa.org · Metrics SLI, SLA, SLO Four golden signals: latency, traffic, errors, saturation 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4@xeraa

Automatic InstrumentationMinimal app modification

@xeraa

Page 45: Tracing - xeraa.org · Metrics SLI, SLA, SLO Four golden signals: latency, traffic, errors, saturation 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4@xeraa

— .NET:

app.UseElasticApm(Configuration);

— Node.js:

const apm = require('elastic-apm-node').start()

— Python:

apm = elasticapm.instrument()

— Ruby on Rails:

config.elastic_apm.service_name = 'MyApp'

@xeraa

Page 46: Tracing - xeraa.org · Metrics SLI, SLA, SLO Four golden signals: latency, traffic, errors, saturation 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4@xeraa

Automatic InstrumentationJava

java -javaagent:/app/elastic-apm-agent.jar -jar /app/app.jar

@xeraa

Page 47: Tracing - xeraa.org · Metrics SLI, SLA, SLO Four golden signals: latency, traffic, errors, saturation 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4@xeraa

Automatic InstrumentationConfiguration

environment: - ELASTIC_APM_SERVICE_NAME=${ELASTIC_APM_SERVICE_NAME:-my-app} - ELASTIC_APM_SERVER_URL=${ELASTIC_APM_SERVER_URL:-http://apm-server:8200} - ELASTIC_APM_APPLICATION_PACKAGES=net.xeraa.my-app - ELASTIC_APM_ENABLE_LOG_CORRELATION=true - ELASTIC_APM_ENVIRONMENT=production

@xeraa

Page 48: Tracing - xeraa.org · Metrics SLI, SLA, SLO Four golden signals: latency, traffic, errors, saturation 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4@xeraa

Supported Technologies

https://www.elastic.co/guide/en/apm/agent/java/1.x/supported-technologies-details.html

@xeraa

Page 49: Tracing - xeraa.org · Metrics SLI, SLA, SLO Four golden signals: latency, traffic, errors, saturation 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4@xeraa

More TricksInferring spans with async-

profiler (20ms default)Avoid safepoint bias and stop-the-world pauses compared to ThreadMXBean#getThreadInfo,

Thread#getStackTrace(),...https://psy-lob-saw.blogspot.com/2016/02/why-most-sampling-java-profilers-are.html

@xeraa

Page 50: Tracing - xeraa.org · Metrics SLI, SLA, SLO Four golden signals: latency, traffic, errors, saturation 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4@xeraa

PS: KubernetesInjection through initContainers

https://www.elastic.co/blog/using-elastic-apm-java-agent-on-kubernetes-k8s

@xeraa

Page 51: Tracing - xeraa.org · Metrics SLI, SLA, SLO Four golden signals: latency, traffic, errors, saturation 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4@xeraa

Manual Instrumentation

Built-in instrumentation supportWrap code manually

@xeraa

Page 52: Tracing - xeraa.org · Metrics SLI, SLA, SLO Four golden signals: latency, traffic, errors, saturation 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4@xeraa

Golanghttp.Server{ Handler: myHandler,}

!

import "go.elastic.co/apm/module/apmhttp"http.Server{ Handler: apmhttp.Wrap(myHandler),}

@xeraa

Page 53: Tracing - xeraa.org · Metrics SLI, SLA, SLO Four golden signals: latency, traffic, errors, saturation 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4@xeraa

Manual Instrumentation

<dependencies> <dependency> <groupId>co.elastic.apm</groupId> <artifactId>apm-agent-api</artifactId> <version>1.13.0</version> </dependency> <dependency> <groupId>co.elastic.apm</groupId> <artifactId>apm-opentracing</artifactId> <version>1.13.0</version> </dependency></dependencies>

@xeraa

Page 54: Tracing - xeraa.org · Metrics SLI, SLA, SLO Four golden signals: latency, traffic, errors, saturation 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4@xeraa

Manual Instrumentation

@GetMapping(value = "/products")@CaptureSpan("Annotation products span")Collection<ProductList> products() { ElasticApm.currentSpan().addTag("foo", "bar"); return productRepository.findAllList();}

@xeraa

Page 55: Tracing - xeraa.org · Metrics SLI, SLA, SLO Four golden signals: latency, traffic, errors, saturation 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4@xeraa

Manual InstrumentationOpenTracing

@GetMapping("/products/{productId}")ProductDetail product(@PathVariable long productId) { final Span span = tracer.buildSpan("OpenTracing product span") .withTag("productId", Long.toString(productId)).start(); try (Scope scope = tracer.scopeManager().activate(span, false)) { return productRepository.getOneDetail(productId); } finally { span.finish(); }}

@xeraa

Page 56: Tracing - xeraa.org · Metrics SLI, SLA, SLO Four golden signals: latency, traffic, errors, saturation 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4@xeraa

PS: Jaeger Intake

apm-server: jaeger: grpc: enabled: true host: "localhost:14250"

@xeraa

Page 57: Tracing - xeraa.org · Metrics SLI, SLA, SLO Four golden signals: latency, traffic, errors, saturation 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4@xeraa

Transactions

Page 58: Tracing - xeraa.org · Metrics SLI, SLA, SLO Four golden signals: latency, traffic, errors, saturation 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4@xeraa
Page 59: Tracing - xeraa.org · Metrics SLI, SLA, SLO Four golden signals: latency, traffic, errors, saturation 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4@xeraa

Errors

Page 60: Tracing - xeraa.org · Metrics SLI, SLA, SLO Four golden signals: latency, traffic, errors, saturation 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4@xeraa
Page 61: Tracing - xeraa.org · Metrics SLI, SLA, SLO Four golden signals: latency, traffic, errors, saturation 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4@xeraa

Metrics

Page 62: Tracing - xeraa.org · Metrics SLI, SLA, SLO Four golden signals: latency, traffic, errors, saturation 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4@xeraa
Page 63: Tracing - xeraa.org · Metrics SLI, SLA, SLO Four golden signals: latency, traffic, errors, saturation 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4@xeraa

Data in a TraceJust another index

Elastic Common Schema (ECS)

@xeraa

Page 64: Tracing - xeraa.org · Metrics SLI, SLA, SLO Four golden signals: latency, traffic, errors, saturation 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4@xeraa
Page 65: Tracing - xeraa.org · Metrics SLI, SLA, SLO Four golden signals: latency, traffic, errors, saturation 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4@xeraa

Scale & Cleanup: ILM (modified){ "policy" : { "phases" : { "hot" : { "min_age" : "0ms", "actions" : { "rollover" : { "max_size" : "50gb", "max_age" : "30d" } } }, "delete" : { "min_age" : "30d", "actions" : { "delete" : { }

Page 66: Tracing - xeraa.org · Metrics SLI, SLA, SLO Four golden signals: latency, traffic, errors, saturation 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4@xeraa

Overhead*: LatencyReport on background thread

Avoid data structures with lock contention

Avoid GC with an object pool* https://discuss.elastic.co/t/dec-15th-2018-en-apm-overhead-of-the-java-agent/160559

@xeraa

Page 67: Tracing - xeraa.org · Metrics SLI, SLA, SLO Four golden signals: latency, traffic, errors, saturation 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4@xeraa

Lifecycle

https://github.com/elastic/apm-agent-java/blob/master/apm-agent-core/README.md#lifecycle

Page 68: Tracing - xeraa.org · Metrics SLI, SLA, SLO Four golden signals: latency, traffic, errors, saturation 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4@xeraa

In single-threaded benchmarks, our Java agent imposes an overhead in the

order of single-digit microseconds (µs) up to the

99.99th percentile.@xeraa

Page 69: Tracing - xeraa.org · Metrics SLI, SLA, SLO Four golden signals: latency, traffic, errors, saturation 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4@xeraa

Overhead: MemoryStatic overhead for object pools

and small buffersOrder of a couple of megabytes

@xeraa

Page 70: Tracing - xeraa.org · Metrics SLI, SLA, SLO Four golden signals: latency, traffic, errors, saturation 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4@xeraa

When disabling header recording, the agent allocates

less than one byte for recording an HTTP request and

one JDBC (SQL) query, including reporting [...]@xeraa

Page 71: Tracing - xeraa.org · Metrics SLI, SLA, SLO Four golden signals: latency, traffic, errors, saturation 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4@xeraa

"Our agent has zero overhead"

!

@xeraa

Page 72: Tracing - xeraa.org · Metrics SLI, SLA, SLO Four golden signals: latency, traffic, errors, saturation 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4@xeraa

Conclusion

@xeraa

Page 73: Tracing - xeraa.org · Metrics SLI, SLA, SLO Four golden signals: latency, traffic, errors, saturation 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4@xeraa

ToolsLogs

MetricsUptimeTraces

@xeraa

Page 74: Tracing - xeraa.org · Metrics SLI, SLA, SLO Four golden signals: latency, traffic, errors, saturation 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4@xeraa

Distributed TracingWhy & how

@xeraa

Page 75: Tracing - xeraa.org · Metrics SLI, SLA, SLO Four golden signals: latency, traffic, errors, saturation 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4@xeraa

Elastic APM & StackCutting edge, free, unified

@xeraa

Page 76: Tracing - xeraa.org · Metrics SLI, SLA, SLO Four golden signals: latency, traffic, errors, saturation 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4@xeraa

Try Ithttps://github.com/elastic/

opbeans-java

@xeraa

Page 77: Tracing - xeraa.org · Metrics SLI, SLA, SLO Four golden signals: latency, traffic, errors, saturation 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4@xeraa
Page 78: Tracing - xeraa.org · Metrics SLI, SLA, SLO Four golden signals: latency, traffic, errors, saturation 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4@xeraa

Tracingfor Java Developers

Philipp Krenn@xeraa

@xeraa