@ -156,7 +156,7 @@ A distributed trace is data that tracks an application request as it flows throu
### Usage
### Usage
Grafana currently supports two tracing implementations, [OpenTelemetry](https://opentelemetry.io/) and [OpenTracing](https://opentracing.io/). OpenTracing is deprecated, but still supported until we remove it. The two different implementations implements the `Tracer` and `Span` interfaces, defined in the _pkg/infra/tracing_ package, which you can use to create traces and spans. To get a hold of a `Tracer` you would need to get it injected as dependency into your service, see [Services](services.md) for more details.
Grafana uses [OpenTelemetry](https://opentelemetry.io/) for distributed tracing. There's an interface `Tracer` in the _pkg/infra/tracing_ package that implements the [OpenTelemetry Tracer interface](go.opentelemetry.io/otel/trace), which you can use to create traces and spans. To get a hold of a `Tracer` you would need to get it injected as dependency into your service, see [Services](services.md) for more details. For more information, see https://opentelemetry.io/docs/instrumentation/go/manual/.
@ -243,6 +244,22 @@ If span names, attribute or event values originates from user input they **shoul
Be **careful** to not expose any sensitive information in span names, attribute or event values, e.g. secrets, credentials etc.
Be **careful** to not expose any sensitive information in span names, attribute or event values, e.g. secrets, credentials etc.
### Span attributes
Consider using `attributes.<Type>("<key>", <value>)` in favor of `attributes.Key("<key>").<Type>(<value>)` since it requires less characters and thereby reads easier.
### How to collect, visualize and query traces (and correlate logs with traces) locally
### How to collect, visualize and query traces (and correlate logs with traces) locally
#### 1. Start Jaeger
#### 1. Start Jaeger
@ -255,20 +272,11 @@ make devenv sources=jaeger
To enable tracing in Grafana, you must set the address in your config.ini file
To enable tracing in Grafana, you must set the address in your config.ini file
opentelemetry tracing (recommended):
```ini
```ini
[tracing.opentelemetry.jaeger]
[tracing.opentelemetry.jaeger]
address = http://localhost:14268/api/traces
address = http://localhost:14268/api/traces
```
```
opentracing tracing (deprecated/not recommended):
```ini
[tracing.jaeger]
address = localhost:6831
```
#### 3. Search/browse collected logs and traces in Grafana Explore
#### 3. Search/browse collected logs and traces in Grafana Explore
You need provisioned gdev-jaeger and gdev-loki datasources, see [developer dashboard and data sources](https://github.com/grafana/grafana/tree/main/devenv#developer-dashboards-and-data-sources) for setup instructions.
You need provisioned gdev-jaeger and gdev-loki datasources, see [developer dashboard and data sources](https://github.com/grafana/grafana/tree/main/devenv#developer-dashboards-and-data-sources) for setup instructions.
plog.Info("Prepared request to Loki","duration",time.Since(start),"queriesLength",len(queries),"stage",stagePrepareRequest,"runInParallel",runInParallel)
plog.Info("Prepared request to Loki","duration",time.Since(start),"queriesLength",len(queries),"stage",stagePrepareRequest,"runInParallel",runInParallel)