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

[docs] Add docs about span macros #4918

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 20 additions & 4 deletions docs/source/customizations/native.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -234,17 +234,17 @@ plugins:
# Any values here are passed to the plugin as part of your configuration
```

## Add custom metrics
## Using macros
To create custom metrics, traces, and spans, you can use [`tracing` macros](https://docs.rs/tracing/latest/tracing/index.html#macros) to generate events and logs.

### Add custom metrics
<Note>

Make sure to [enable prometheus metrics](../configuration/telemetry/exporters/metrics/prometheus) in your configuration if you want to have metrics generated by the Router.

</Note>

### Using macros

To create your custom metrics in [Prometheus](https://prometheus.io/) you can use the [tracing macros](https://docs.rs/tracing/latest/tracing/index.html#macros) to generate an event.
To create your custom metrics in [Prometheus](https://prometheus.io/) you can use [event macros](https://docs.rs/tracing/latest/tracing/index.html#macros) to generate an event.
If you observe a specific naming pattern for your event you'll be able to generate your own custom metrics directly in Prometheus.

To publish a new metric, use tracing macros to generate an event that contains one of the following prefixes:
Expand Down Expand Up @@ -281,6 +281,22 @@ tracing::info!(
);
```

### Add custom spans
<Note>

Make sure to [enable OpenTelemetry tracing](../configuration/telemetry/exporters/tracing/overview) in your configuration if you want customize the traces generated and linked by the router.

</Note>

To create custom spans and traces you can use [`tracing` macros](https://docs.rs/tracing/latest/tracing/index.html#macros) to generate a span.

```rust
use tracing::info_span;

info_span!("my_span");
```


## Plugin Lifecycle

Like individual requests, plugins follow their own strict lifecycle that helps provide structure to the Apollo Router's execution.
Expand Down