Skip to content

Commit

Permalink
feat: add OpenTelemetry
Browse files Browse the repository at this point in the history
  • Loading branch information
KateKate authored and awinogradov committed Nov 14, 2023
1 parent 04d97b9 commit 04e03da
Show file tree
Hide file tree
Showing 5 changed files with 892 additions and 17 deletions.
18 changes: 18 additions & 0 deletions instrumentation.node.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { NodeSDK } from '@opentelemetry/sdk-node';
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-http';
import { Resource } from '@opentelemetry/resources';
import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions';
import { BatchSpanProcessor } from '@opentelemetry/sdk-trace-node';

const serviceEnvironment = process.env.SERVICE_ENVIRONMENT || 'unknown';
const commitHash = process.env.CI_COMMIT_SHORT_SHA || 'unknown';

const sdk = new NodeSDK({
resource: new Resource({
[SemanticResourceAttributes.SERVICE_NAME]: `issues-${serviceEnvironment}-${commitHash}`,
[SemanticResourceAttributes.K8S_POD_NAME]: process.env.HOSTNAME,
[SemanticResourceAttributes.K8S_CLUSTER_NAME]: process.env.CLUSTER_URL,
}),
spanProcessor: new BatchSpanProcessor(new OTLPTraceExporter()),
});
sdk.start();
5 changes: 5 additions & 0 deletions instrumentation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export async function register() {
if (process.env.NEXT_RUNTIME === 'nodejs') {
await import('./instrumentation.node');
}
}
3 changes: 3 additions & 0 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ const withMDX = require('@next/mdx')({

/** @type {import('next').NextConfig} */
const nextConfig = {
experimental: {
instrumentationHook: true,
},
compiler: {
styledComponents: {
ssr: true,
Expand Down
Loading

0 comments on commit 04e03da

Please sign in to comment.