Skip to content

Commit

Permalink
add back in manual instrumentation
Browse files Browse the repository at this point in the history
  • Loading branch information
branberry committed Oct 27, 2023
1 parent ae46c5c commit 0d96010
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Dockerfile.enhanced
Original file line number Diff line number Diff line change
Expand Up @@ -117,4 +117,4 @@ ENV OAS_MODULE_PATH=${WORK_DIRECTORY}/modules/oas-page-builder/index.js

RUN mkdir repos && chmod 755 repos
EXPOSE 3000
CMD ["node", "--require", "@opentelemetry/auto-instrumentations-node/register", "enhanced/enhancedApp.js"]
CMD ["node", "enhanced/enhancedApp.js"]
10 changes: 10 additions & 0 deletions src/enhanced/enhancedApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import mongodb, { MongoClient } from 'mongodb';
import c from 'config';
import { handleJob } from './utils/job';
import { listenToJobQueue } from './utils/queue';
import { nodeSDKBuilder } from '../otel';

let client: MongoClient | undefined;

Expand Down Expand Up @@ -49,6 +50,9 @@ async function handleJobAndCleanUp(jobId: string, db: mongodb.Db) {
await cleanupJob();
}
}

const sdk = nodeSDKBuilder();

async function app(): Promise<void> {
console.log('[app]: starting application');

Expand All @@ -69,4 +73,10 @@ app();

process.on('SIGTERM', async () => {
await cleanupJob();

sdk
.shutdown()
.then(() => console.log('Tracing and Metrics terminated'))
.catch((error) => console.log('Error terminating tracing and metrics', error))
.finally(() => process.exit(0));
});
37 changes: 37 additions & 0 deletions src/otel/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { NodeSDK } from '@opentelemetry/sdk-node';
import { AWSXRayPropagator } from '@opentelemetry/propagator-aws-xray';

import { detectResourcesSync } from '@opentelemetry/resources';
import { awsEcsDetector } from '@opentelemetry/resource-detector-aws';
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-grpc';
import { BatchSpanProcessor } from '@opentelemetry/sdk-trace-base';
import { HttpInstrumentation } from '@opentelemetry/instrumentation-http';
import { AwsInstrumentation } from '@opentelemetry/instrumentation-aws-sdk';
import { AWSXRayIdGenerator } from '@opentelemetry/id-generator-aws-xray';

export function nodeSDKBuilder() {
const resource = detectResourcesSync({
detectors: [awsEcsDetector],
});

const traceExporter = new OTLPTraceExporter();
const spanProcessor = new BatchSpanProcessor(traceExporter);

const sdk = new NodeSDK({
textMapPropagator: new AWSXRayPropagator(),
instrumentations: [
new HttpInstrumentation(),
new AwsInstrumentation({
suppressInternalInstrumentation: true,
}),
],
idGenerator: new AWSXRayIdGenerator(),
resource,
traceExporter,
spanProcessor,
});

sdk.start();

return sdk;
}

0 comments on commit 0d96010

Please sign in to comment.