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 Sep 29, 2023
1 parent a21d368 commit 154e262
Show file tree
Hide file tree
Showing 6 changed files with 219 additions and 45 deletions.
189 changes: 147 additions & 42 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 @@ -24,7 +24,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 @@ -33,6 +33,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 @@ -21,7 +21,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 @@ -31,6 +31,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'],
},
);
2 changes: 1 addition & 1 deletion packages/search/test.http
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ POST {{api_host}}/chat
Content-Type: application/json

{
"history": [{ "user": "What happens is a rental doesn't fit the description?" }],
"history": [{ "user": "What happens if a rental doesn't fit the description?" }],
"approach":"rrr",
"overrides": {
"retrieval_mode": "hybrid",
Expand Down

0 comments on commit 154e262

Please sign in to comment.