Skip to content
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

how to get a meter and tracer with agent and spring starter #4647

Merged
merged 8 commits into from
Jun 12, 2024
60 changes: 60 additions & 0 deletions content/en/docs/languages/java/instrumentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,35 @@ Tracer tracer = GlobalOpenTelemetry.getTracer("instrumentation-scope-name", "ins
Note that you can't force end users to configure the global, so this is the most
brittle option for library instrumentation.

### Acquiring a Tracer in Java Agent

If you are writing a Java Agent, you can acquire a `Tracer` from the global
zeitlinger marked this conversation as resolved.
Show resolved Hide resolved
OpenTelemetry instance:

```java
import io.opentelemetry.api.GlobalOpenTelemetry;

Tracer tracer = GlobalOpenTelemetry.getTracer("instrumentation-scope-name");
```

### Acquiring a Tracer in Spring Boot starter

If you are writing a Spring Boot starter, you can acquire a `Tracer` from the
zeitlinger marked this conversation as resolved.
Show resolved Hide resolved
autowired OpenTelemetry instance:

```java
import io.opentelemetry.api.OpenTelemetry;
import io.opentelemetry.api.trace.Tracer;

public class MyController {
private final Tracer tracer;

public MyController(OpenTelemetry openTelemetry) {
this.tracer = openTelemetry.getTracer("instrumentation-scope-name");
}
}
```

### Create Spans

Now that you have [tracers](/docs/concepts/signals/traces/#tracer) initialized,
Expand Down Expand Up @@ -1216,6 +1245,37 @@ Now that you have [meters](/docs/concepts/signals/metrics/#meter) initialized.
you can create
[metric instruments](/docs/concepts/signals/metrics/#metric-instruments).

### Acquiring a Meter in Java Agent

If you are writing a Java Agent, you can acquire a `Meter` from the global
zeitlinger marked this conversation as resolved.
Show resolved Hide resolved
OpenTelemetry instance:

```java
import io.opentelemetry.api.GlobalOpenTelemetry;

Meter meter = GlobalOpenTelemetry.getMeter("instrumentation-scope-name");
```

### Acquiring a Meter in Spring Boot starter

If you are writing a Spring Boot starter, you can acquire a `Meter` from the
zeitlinger marked this conversation as resolved.
Show resolved Hide resolved
autowired OpenTelemetry instance:

```java
import io.opentelemetry.api.OpenTelemetry;
import io.opentelemetry.api.metrics.Meter;

public class MyController {
private final Meter meter;

public MyController(OpenTelemetry openTelemetry) {
this.meter = openTelemetry.getMeter("instrumentation-scope-name");
}
}
```

a

### Using Counters

Counters can be used to measure non-negative, increasing values.
Expand Down