Skip to content

Commit 13effbd

Browse files
jkwatsonanuraaga
andauthored
update the QUICKSTART for 0.15.0 (open-telemetry#2615)
* update the QUICKSTART for 0.15.0 * Update QUICKSTART.md Co-authored-by: Anuraag Agrawal <anuraaga@gmail.com> * Update QUICKSTART.md Co-authored-by: Anuraag Agrawal <anuraaga@gmail.com> * Update QUICKSTART.md Co-authored-by: Anuraag Agrawal <anuraaga@gmail.com> * update the docs based on feedback Co-authored-by: Anuraag Agrawal <anuraaga@gmail.com>
1 parent 85382fd commit 13effbd

1 file changed

Lines changed: 39 additions & 47 deletions

File tree

QUICKSTART.md

Lines changed: 39 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ Tracer tracer =
7979
Important: the "name" and optional version of the tracer are purely informational.
8080
All `Tracer`s that are created by a single `OpenTelemetry` instance will interoperate, regardless of name.
8181

82-
### Create basic Span
82+
### Create a basic Span
8383
To create a basic span, you only need to specify the name of the span.
8484
The start and end time of the span is automatically set by the OpenTelemetry SDK.
8585
```java
@@ -103,17 +103,17 @@ processes, see [Context Propagation](#context-propagation).
103103

104104
For a method `a` calling a method `b`, the spans could be manually linked in the following way:
105105
```java
106-
void a() {
107-
Span parentSpan = tracer.spanBuilder("a").startSpan();
106+
void parentOne() {
107+
Span parentSpan = tracer.spanBuilder("parent").startSpan();
108108
try {
109-
b(parentSpan);
109+
childOne(parentSpan);
110110
} finally {
111111
parentSpan.end();
112112
}
113113
}
114114

115-
void b(Span parentSpan) {
116-
Span childSpan = tracer.spanBuilder("b")
115+
void childOne(Span parentSpan) {
116+
Span childSpan = tracer.spanBuilder("child")
117117
.setParent(Context.current().with(parentSpan))
118118
.startSpan();
119119
// do stuff
@@ -122,16 +122,16 @@ void b(Span parentSpan) {
122122
```
123123
The OpenTelemetry API offers also an automated way to propagate the parent span on the current thread:
124124
```java
125-
void a() {
126-
Span parentSpan = tracer.spanBuilder("a").startSpan();
125+
void parentTwo() {
126+
Span parentSpan = tracer.spanBuilder("parent").startSpan();
127127
try(Scope scope = parentSpan.makeCurrent()) {
128-
b();
128+
childTwo();
129129
} finally {
130130
parentSpan.end();
131131
}
132132
}
133-
void b() {
134-
Span childSpan = tracer.spanBuilder("b")
133+
void childTwo() {
134+
Span childSpan = tracer.spanBuilder("child")
135135
// NOTE: setParent(...) is not required;
136136
// `Span.current()` is automatically added as the parent
137137
.startSpan();
@@ -243,7 +243,7 @@ The following presents an example of processing an incoming HTTP request using
243243

244244
```java
245245
TextMapPropagator.Getter<HttpExchange> getter =
246-
new TextMapPropagator.Getter<HttpExchange>() {
246+
new TextMapPropagator.Getter<>() {
247247
@Override
248248
public String get(HttpExchange carrier, String key) {
249249
if (carrier.getRequestHeaders().containsKey(key)) {
@@ -303,7 +303,7 @@ The following is an example of counter usage:
303303

304304
```java
305305
// Gets or creates a named meter instance
306-
Meter meter = meterProvider.getMeter("instrumentation-library-name", "1.0.0");
306+
Meter meter = meterProvider.get("instrumentation-library-name", "1.0.0");
307307

308308
// Build counter e.g. LongCounter
309309
LongCounter counter = meter
@@ -330,21 +330,15 @@ collecting metric data on demand, once per collection interval.
330330
The following is an example of observer usage:
331331

332332
```java
333-
// Build observer e.g. LongObserver
334-
LongObserver observer = meter
335-
.observerLongBuilder("cpu_usage")
333+
// Build observer e.g. LongSumObserver
334+
LongSumObserver observer = meter
335+
.longSumObserverBuilder("cpu_usage")
336336
.setDescription("CPU Usage")
337337
.setUnit("ms")
338+
.setUpdater(result -> {
339+
result.observe(getCpuUsage(), Labels.of("Key", "SomeWork"));
340+
})
338341
.build();
339-
340-
observer.setCallback(
341-
new LongObserver.Callback<LongObserver.ResultLongObserver>() {
342-
@Override
343-
public void update(ResultLongObserver result) {
344-
// long getCpuUsage()
345-
result.observe(getCpuUsage(), Labels.of("Key", "SomeWork"));
346-
}
347-
});
348342
```
349343

350344
## Tracing SDK Configuration
@@ -381,13 +375,12 @@ Additional samplers can be provided by implementing the `io.opentelemetry.sdk.tr
381375
interface.
382376

383377
```java
384-
TraceConfig alwaysOn = TraceConfig.getDefault().toBuilder().setSampler(Sampler.alwaysOn()).build();
385-
TraceConfig alwaysOff = TraceConfig.getDefault().toBuilder().setSampler(Sampler.alwaysOff()).build();
386-
TraceConfig half = TraceConfig.getDefault().toBuilder().setSampler(Sampler.traceIdRatioBased(0.5)).build();
387-
388-
// You configure the sampler when building the SDK implementation:
389378
SdkTracerProvider tracerProvider = SdkTracerProvider.builder()
390-
.setTraceConfig(half)
379+
.setSampler(Sampler.alwaysOn())
380+
//or
381+
.setSampler(Sampler.alwaysOff())
382+
//or
383+
.setSampler(Sampler.traceIdRatioBased(0.5))
391384
.build();
392385
```
393386

@@ -400,12 +393,9 @@ in bulk. Multiple Span processors can be configured to be active at the same tim
400393

401394
```java
402395
SdkTracerProvider tracerProvider = SdkTracerProvider.builder()
403-
.addSpanProcessor(
404-
MultiSpanProcessor.create(Arrays.asList(
405-
SimpleSpanProcessor.create(new LoggingSpanExporter()),
406-
BatchSpanProcessor.builder(new LoggingSpanExporter()).build()
407-
)))
408-
.build();
396+
.addSpanProcessor(SimpleSpanProcessor.create(new LoggingSpanExporter()))
397+
.addSpanProcessor(BatchSpanProcessor.builder(new LoggingSpanExporter()).build())
398+
.build();
409399
```
410400

411401
### Exporter
@@ -421,14 +411,18 @@ a particular backend. OpenTelemetry offers five exporters out of the box:
421411
Other exporters can be found in the [OpenTelemetry Registry].
422412

423413
```java
424-
ManagedChannel jaegerChannel =
425-
ManagedChannelBuilder.forAddress([ip:String], [port:int]).usePlaintext().build();
414+
ManagedChannel jaegerChannel = ManagedChannelBuilder.forAddress("localhost", 3336)
415+
.usePlaintext()
416+
.build();
417+
426418
JaegerGrpcSpanExporter jaegerExporter = JaegerGrpcSpanExporter.builder()
427-
.setServiceName("example").setChannel(jaegerChannel).setDeadline(30000)
428-
.build()
419+
.setEndpoint("localhost:3336")
420+
.setTimeout(30, TimeUnit.SECONDS)
421+
.build();
429422

430-
SdkTracerProvider tracerProvider = SdkTracerProvider.builder().build();
431-
tracerProvider.addSpanProcessor(BatchSpanProcessor.builder(jaegerExporter).build()));
423+
SdkTracerProvider tracerProvider = SdkTracerProvider.builder()
424+
.addSpanProcessor(BatchSpanProcessor.builder(jaegerExporter).build())
425+
.build();
432426
```
433427

434428
### Auto Configuration
@@ -444,13 +438,11 @@ Some of the supported system properties and environment variables:
444438

445439
| System property | Environment variable | Purpose |
446440
|----------------------------------|----------------------------------|-----------------------------------------------------------------------------------------------------|
447-
| otel.config.sampler.probability | OTEL_CONFIG_SAMPLER_PROBABILITY | Sampler which is used when constructing a new span (default: 1) |
441+
| otel.trace.sampler | OTEL_TRACE_SAMPLER | Which sampler to use (`parentbased_traceidratio` for example)
442+
| otel.trace.sampler.arg | OTEL_TRACE_SAMPLER_ARG | Used to configured the ratio for the ratio-based sampler (default: 1) |
448443
| otel.span.attribute.count.limit | OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT | Max number of attributes per span, extra will be dropped (default: 1000) |
449444
| otel.span.event.count.limit | OTEL_SPAN_EVENT_COUNT_LIMIT | Max number of Events per span, extra will be dropped (default: 1000) |
450445
| otel.span.link.count.limit | OTEL_SPAN_LINK_COUNT_LIMIT | Max number of Link entries per span, extra will be dropped (default: 1000) |
451-
| otel.config.max.event.attrs | OTEL_CONFIG_MAX_EVENT_ATTRS | Max number of attributes per event, extra will be dropped (default: 32) |
452-
| otel.config.max.link.attrs | OTEL_CONFIG_MAX_LINK_ATTRS | Max number of attributes per link, extra will be dropped (default: 32) |
453-
| otel.config.max.attr.length | OTEL_CONFIG_MAX_ATTR_LENGTH | Max length of string attribute value in characters, too long will be truncated (default: unlimited) |
454446

455447
[AlwaysOnSampler]: https://github.com/open-telemetry/opentelemetry-java/blob/main/sdk/tracing/src/main/java/io/opentelemetry/sdk/trace/samplers/Sampler.java#L29
456448
[AlwaysOffSampler]:https://github.com/open-telemetry/opentelemetry-java/blob/main/sdk/tracing/src/main/java/io/opentelemetry/sdk/trace/samplers/Sampler.java#L40

0 commit comments

Comments
 (0)