Skip to content

Commit

Permalink
feat: WIP add opentelemetry configuration (#58)
Browse files Browse the repository at this point in the history
  • Loading branch information
sinedied committed Oct 13, 2023
1 parent 4b70e20 commit 5ca0a43
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 4 deletions.
8 changes: 6 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion packages/indexer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
},
"dependencies": {
"@azure/identity": "^3.3.0",
"@azure/monitor-opentelemetry": "^1.0.0-beta.2",
"@azure/monitor-opentelemetry": "^1.0.0",
"@azure/search-documents": "^12.0.0-beta.3",
"@azure/storage-blob": "^12.15.0",
"@dqbd/tiktoken": "^1.0.7",
Expand All @@ -34,6 +34,8 @@
"@fastify/multipart": "^7.7.3",
"@fastify/sensible": "^5.0.0",
"@fastify/type-provider-json-schema-to-ts": "^2.2.2",
"@opentelemetry/instrumentation": "^0.43.0",
"@opentelemetry/instrumentation-fastify": "^0.32.2",
"commander": "^11.0.0",
"dotenv": "^16.3.1",
"fastify": "^4.22.2",
Expand Down
32 changes: 32 additions & 0 deletions packages/indexer/src/plugins/opentelemetry.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import fp from 'fastify-plugin';
import { useAzureMonitor, type AzureMonitorOpenTelemetryOptions } from '@azure/monitor-opentelemetry';
import { registerInstrumentations } from '@opentelemetry/instrumentation';
import { FastifyInstrumentation } from '@opentelemetry/instrumentation-fastify';

export default fp(
async (fastify) => {
const { applicationInsightsConnectionString } = fastify.config;
if (applicationInsightsConnectionString) {
const options: AzureMonitorOpenTelemetryOptions = {
azureMonitorExporterOptions: {
connectionString: applicationInsightsConnectionString,
},
};
useAzureMonitor(options);

registerInstrumentations({
instrumentations: [
// Azure monitor already instruments HTTP layer by default,
// so we don't need to add instrumentation for it
new FastifyInstrumentation(),
],
});
} else {
fastify.log.info('Application Insights configuration not found, OpenTelemetry disabled');
}
},
{
name: 'opentelemetry',
dependencies: ['config'],
},
);
4 changes: 3 additions & 1 deletion packages/search/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
},
"dependencies": {
"@azure/identity": "^3.3.0",
"@azure/monitor-opentelemetry": "^1.0.0-beta.2",
"@azure/monitor-opentelemetry": "^1.0.0",
"@azure/search-documents": "^12.0.0-beta.3",
"@azure/storage-blob": "^12.15.0",
"@dqbd/tiktoken": "^1.0.7",
Expand All @@ -32,6 +32,8 @@
"@fastify/swagger": "^8.10.0",
"@fastify/swagger-ui": "^1.9.3",
"@fastify/type-provider-json-schema-to-ts": "^2.2.2",
"@opentelemetry/instrumentation": "^0.43.0",
"@opentelemetry/instrumentation-fastify": "^0.32.2",
"dotenv": "^16.3.1",
"fastify": "^4.0.0",
"fastify-cli": "^5.7.0",
Expand Down
33 changes: 33 additions & 0 deletions packages/search/src/plugins/opentelemetry.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import fp from 'fastify-plugin';
import { useAzureMonitor, type AzureMonitorOpenTelemetryOptions } from '@azure/monitor-opentelemetry';
import { registerInstrumentations } from '@opentelemetry/instrumentation';
import { FastifyInstrumentation } from '@opentelemetry/instrumentation-fastify';

export default fp(
async (fastify) => {
const { applicationInsightsConnectionString } = fastify.config;
if (applicationInsightsConnectionString) {
fastify.log.info('Application Insights configuration found, OpenTelemetry enabled');
const options: AzureMonitorOpenTelemetryOptions = {
azureMonitorExporterOptions: {
connectionString: applicationInsightsConnectionString,
},
};
useAzureMonitor(options);

registerInstrumentations({
instrumentations: [
// Azure monitor already instruments HTTP layer by default,
// so we don't need to add instrumentation for it
new FastifyInstrumentation(),
],
});
} else {
fastify.log.info('Application Insights configuration not found, OpenTelemetry disabled');
}
},
{
name: 'opentelemetry',
dependencies: ['config'],
},
);

0 comments on commit 5ca0a43

Please sign in to comment.