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: Updated Next.js Otel cloud provider FAQ #2537

Merged
merged 1 commit into from
Sep 3, 2024
Merged
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
63 changes: 42 additions & 21 deletions documentation/nextjs/faqs/cloud-providers.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,32 +21,35 @@ To setup Next.js to load OpenTelemetry data to New Relic you must do the followi
2. Install OpenTelemetry packages.

```sh
npm install @opentelemetry/sdk-node @opentelemetry/resources @opentelemetry/semantic-conventions @opentelemetry/sdk-trace-node @opentelemetry/exporter-trace-otlp-http
npm @opentelemetry/api @opentelemetry/auto-instrumentations-node @opentelemetry/exporter-metrics-otlp-proto @opentelemetry/exporter-trace-otlp-proto @opentelemetry/sdk-metrics @opentelemetry/sdk-node @opentelemetry/sdk-trace-node"
```

3. Setup OpenTelemetry configuration in `new-relic-instrumentation.js`

```js
const { NodeSDK } = require('@opentelemetry/sdk-node')
const { getNodeAutoInstrumentations } = require('@opentelemetry/auto-instrumentations-node')
const { OTLPTraceExporter } = require('@opentelemetry/exporter-trace-otlp-http')
const { Resource } = require('@opentelemetry/resources')
const { SemanticResourceAttributes } = require('@opentelemetry/semantic-conventions')
const { SimpleSpanProcessor } = require('@opentelemetry/sdk-trace-node')

const sdk = new NodeSDK({
resource: new Resource({
[SemanticResourceAttributes.SERVICE_NAME]: 'next-app',
const opentelemetry = require('@opentelemetry/sdk-node');
const {
getNodeAutoInstrumentations,
} = require('@opentelemetry/auto-instrumentations-node');
const {
OTLPTraceExporter,
} = require('@opentelemetry/exporter-trace-otlp-proto');
const {
OTLPMetricExporter,
} = require('@opentelemetry/exporter-metrics-otlp-proto');
const { PeriodicExportingMetricReader } = require('@opentelemetry/sdk-metrics');
const { diag, DiagConsoleLogger, DiagLogLevel } = require('@opentelemetry/api');

diag.setLogger(new DiagConsoleLogger(), DiagLogLevel.INFO);

const sdk = new opentelemetry.NodeSDK({
traceExporter: new OTLPTraceExporter(),
metricReader: new PeriodicExportingMetricReader({
exporter: new OTLPMetricExporter(),
}),
spanProcessor: new SimpleSpanProcessor(new OTLPTraceExporter({
url: 'https://otlp.nr-data.net',
headers: {
'api-key': process.env.NEW_RELIC_API_KEY
}
})),
instrumentations: [getNodeAutoInstrumentations()]
})
sdk.start()
instrumentations: [getNodeAutoInstrumentations()],
});

sdk.start();
```

4. Add the following to `instrumentation.ts` in the root of your Next.js project:
Expand All @@ -59,3 +62,21 @@ export async function register() {
}
```

5. Export the following environment variables:

**Note**: `<your_license_key>` should be a New Relic ingest key.

```sh
export OTEL_SERVICE_NAME=nextjs-otel-app
export OTEL_RESOURCE_ATTRIBUTES=service.instance.id=123
export OTEL_EXPORTER_OTLP_ENDPOINT=https://otlp.nr-data.net
export OTEL_EXPORTER_OTLP_HEADERS=api-key=<your_license_key>
export OTEL_ATTRIBUTE_VALUE_LENGTH_LIMIT=4095
export OTEL_EXPORTER_OTLP_COMPRESSION=gzip
export OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf
export OTEL_EXPORTER_OTLP_METRICS_TEMPORALITY_PREFERENCE=delta
```

For more information on using OpenTelemetry with New Relic, check out this [example application](https://github.com/newrelic/newrelic-opentelemetry-examples/tree/7154872abd2bfd466fa77af4049b4189dcfff99f/getting-started-guides/javascript)