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

feat(otel): expose SDK instance from registerOTel #141

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
19 changes: 12 additions & 7 deletions packages/otel/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,13 @@ To configure OpenTelemetry SDK, call the `registerOTel` in the `instrumentation.
import { registerOTel } from "@vercel/otel";

export function register() {
// Register the OpenTelemetry.
registerOTel("your-service-name");
// Register the OpenTelemetry and get SDK instance
const sdk = registerOTel("your-service-name");

// Optionally store SDK instance for shutdown
process.on("SIGTERM", async () => {
await sdk.shutdown();
});
}
```

Expand All @@ -36,15 +41,15 @@ const span = trace.getTracer("your-component").startSpan("your-operation");

## 📖 API Reference

### `registerOTel(serviceName: string)`
### `registerOTel(serviceName: string): Sdk`

Registers the OpenTelemetry SDK with the specified service name and the default configuration.
Registers the OpenTelemetry SDK with the specified service name and the default configuration. Returns SDK instance for managing lifecycle.

- `serviceName`: The name of your service, used as the app name in many OpenTelemetry backends.
- serviceName: The name of your service, used as the app name in many OpenTelemetry backends.

### `registerOTel(config: Configuration)`
### `registerOTel(config: Configuration): Sdk`

Registers the OpenTelemetry SDK with the specified configuration. Configuration options include:
Registers the OpenTelemetry SDK with the specified configuration. Returns SDK instance for managing lifecycle. Configuration options include:

- `serviceName`: The name of your service, used as the app name in many OpenTelemetry backends.
- `attributes`: The resource attributes. By default, `@vercel/otel` configures relevant Vercel attributes based on [the environment](https://vercel.com/docs/projects/environment-variables/system-environment-variables), such as `env`, `vercel.runtime`, `vercel.host`, etc.
Expand Down
4 changes: 3 additions & 1 deletion packages/otel/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export {
*/
export function registerOTel(
optionsOrServiceName?: Configuration | string
): void {
): Sdk {
let options: Configuration;
if (!optionsOrServiceName) {
options = {};
Expand All @@ -40,4 +40,6 @@ export function registerOTel(
}
const sdk = new Sdk(options);
sdk.start();

return sdk;
}