-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merged PR 28496: Azure Monitor tracing for waste-tracking-gateway
Azure Monitor tracing for waste-tracking-gateway Added Application Insights tracing to _waste-tracking-gateway_ via [OpenTelemetry](https://opentelemetry.io/). - Downgraded Hapi from v21 to v20 because unfortunately instrumentation is [not yet provided for v21](open-telemetry/opentelemetry-js-contrib#1383). If this becomes a problem, we can forgo the Hapi layer and rely on just HTTP instrumentation. - Traces will be written to console in development. - Setting `APPINSIGHTS_CONNECTION_STRING` emits traces to Azure Monitor. - This required an additional _tracing.js_ entry point as instrumentation must be loaded first.
- Loading branch information
iwalters
committed
Apr 11, 2023
1 parent
dd05238
commit 21c6fed
Showing
6 changed files
with
1,831 additions
and
535 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
NODE_ENV=production |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,16 @@ | ||
FROM node:18-alpine | ||
|
||
ENV NODE_ENV production | ||
ENV PORT 3000 | ||
ENV NODE_ENV=production \ | ||
PORT=3000 | ||
|
||
WORKDIR /app | ||
COPY --chown=node:node dist/apps/waste-tracking-gateway/main.js ./main.js | ||
COPY --chown=node:node dist/apps/waste-tracking-gateway/tracing.js ./tracing.js | ||
COPY --chown=node:node dist/apps/waste-tracking-gateway/package*.json ./ | ||
|
||
RUN npm ci | ||
|
||
USER node | ||
EXPOSE 3000 | ||
EXPOSE ${PORT} | ||
|
||
CMD [ "main.js" ] | ||
CMD [ "--require", "./tracing.js", "main.js" ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { AzureMonitorTraceExporter } from '@azure/monitor-opentelemetry-exporter'; | ||
import { registerInstrumentations } from '@opentelemetry/instrumentation'; | ||
import { HapiInstrumentation } from '@opentelemetry/instrumentation-hapi'; | ||
import { HttpInstrumentation } from '@opentelemetry/instrumentation-http'; | ||
import { Resource } from '@opentelemetry/resources'; | ||
import { | ||
BatchSpanProcessor, | ||
ConsoleSpanExporter, | ||
} from '@opentelemetry/sdk-trace-base'; | ||
import { NodeTracerProvider } from '@opentelemetry/sdk-trace-node'; | ||
import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions'; | ||
|
||
const provider = new NodeTracerProvider({ | ||
resource: Resource.default().merge( | ||
new Resource({ | ||
[SemanticResourceAttributes.SERVICE_NAME]: | ||
process.env['APP_ID'] || 'waste-tracking-gateway', | ||
}) | ||
), | ||
}); | ||
|
||
if (process.env['NODE_ENV'] === 'development') { | ||
provider.addSpanProcessor(new BatchSpanProcessor(new ConsoleSpanExporter())); | ||
} | ||
|
||
const connectionString = process.env['APPINSIGHTS_CONNECTION_STRING']; | ||
if (connectionString !== undefined) { | ||
provider.addSpanProcessor( | ||
new BatchSpanProcessor(new AzureMonitorTraceExporter({ connectionString })) | ||
); | ||
} | ||
|
||
provider.register(); | ||
registerInstrumentations({ | ||
instrumentations: [new HttpInstrumentation(), new HapiInstrumentation()], | ||
}); |
Oops, something went wrong.