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

Recommend @opentelemetry/api instead of @vercel/otel reexport #48013

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions docs/advanced-features/open-telemetry.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,16 @@ To see more spans, you must set `NEXT_OTEL_VERBOSE=1`.

## Custom Spans

OpenTelemetry enables you to add your own custom spans to trace using official OpenTelemetry APIs.
Our package `@vercel/otel` exports everything from `@opentelemetry/api` so you don't need to install anything.
You can add your own span with [OpenTelemetry APIs](https://opentelemetry.io/docs/instrumentation/js/instrumentation).

```bash
npm install @opentelemetry/api
```

The following example demonstrates a function that fetches GitHub stars and adds a custom `fetchGithubStars` span to track the fetch request's result:

```ts
import { trace } from '@vercel/otel'
import { trace } from '@opentelemetry/api'

export async function fetchGithubStars() {
return await trace
Expand All @@ -77,8 +80,6 @@ export async function fetchGithubStars() {
}
```

More documentation can be found in [OpenTelemetry docs](https://opentelemetry.io/docs/instrumentation/js/instrumentation/).

The `register` function will execute before your code runs in a new environment.
You can start creating new spans, and they should be correctly added to the exported trace.

Expand Down
4 changes: 0 additions & 4 deletions examples/with-opentelemetry/.vscode/settings.json

This file was deleted.

1 change: 1 addition & 0 deletions examples/with-opentelemetry/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
},
"dependencies": {
"@vercel/otel": "latest",
"@opentelemetry/api": "^1.4.1",
"next": "latest",
"react": "^18.2.0",
"react-dom": "^18.2.0"
Expand Down
2 changes: 1 addition & 1 deletion examples/with-opentelemetry/shared/fetch-github-stars.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { trace } from '@vercel/otel'
import { trace } from '@opentelemetry/api'

export async function fetchGithubStars() {
return await trace
Expand Down