Skip to content

instrumentation does not work during deployment Β #606

@abaybektursun

Description

@abaybektursun

I am trying to get OpenTelemtry working with my app (For debugging LLMs). It works when I run it locally, however it stops working after deploying with SST v3 ("sst": "3.2.12")
I have this in my next.config.js

module.exports = {
  experimental: {
    instrumentationHook: true
  }
}

instrumentation.ts

// Ensure this is in the root of your project, not in app or pages directories
export async function register() {
  if (process.env.NEXT_RUNTIME === 'nodejs') {
    await import('./instrumentation.node')
  }
}

instrumentation.node.js

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 { SimpleSpanProcessor } from '@opentelemetry/sdk-trace-node';
import { diag, DiagConsoleLogger, DiagLogLevel } from '@opentelemetry/api';

// Enable //console.logging for OpenTelemetry
diag.setLogger(new DiagConsoleLogger(), DiagLogLevel.DEBUG);

console.log('Starting OpenTelemetry initialization');

const isProduction = process.env.NODE_ENV === 'production';
console.log(`(instrumentation.node.js) Environment: ${isProduction ? 'Production' : 'Development'}`);

const traceExporter = new OTLPTraceExporter({
  url: '.......',
});

//console.log(`Trace exporter URL: ${traceExporter.url}`);

const sdk = new NodeSDK({
  resource: new Resource({
    [SemanticResourceAttributes.SERVICE_NAME]: 'tracing',
    [SemanticResourceAttributes.DEPLOYMENT_ENVIRONMENT]: isProduction ? 'production' : 'development',
  }),
  spanProcessors: [new SimpleSpanProcessor(traceExporter)],
});

// Start the SDK without assuming it returns a Promise
try {
  sdk.start();
  console.log('OpenTelemetry SDK started successfully');
} catch (error) {
  console.error('Error starting OpenTelemetry SDK:', error);
}

process.on('SIGTERM', () => {
  sdk.shutdown()
    .then(() => console.log('Tracing terminated'))
    .catch((error) => console.log('Error terminating tracing', error))
    .finally(() => process.exit(0));
});

console.log('OpenTelemetry setup script finished');

This entire file seems to be ignored since there are no logs from instrumentation.node.js in CloudWatch or SST.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions