Compare commits

...

2 Commits

Author SHA1 Message Date
Anurag Mittal 4f567756d0
options for spans 2024-06-04 23:45:39 +02:00
Anurag Mittal 665f9d9591
S3C-8823: add Otel SDK setup with honeycomb 2024-05-27 09:18:03 +02:00
4 changed files with 1650 additions and 7 deletions

View File

@ -3,6 +3,9 @@ const https = require('https');
const cluster = require('cluster'); const cluster = require('cluster');
const { series } = require('async'); const { series } = require('async');
const arsenal = require('arsenal'); const arsenal = require('arsenal');
// trace and context
const { trace, context } = require('@opentelemetry/api');
const { RedisClient, StatsClient } = arsenal.metrics; const { RedisClient, StatsClient } = arsenal.metrics;
const monitoringClient = require('./utilities/monitoringHandler'); const monitoringClient = require('./utilities/monitoringHandler');
const metrics = require('./utilities/metrics'); const metrics = require('./utilities/metrics');
@ -140,7 +143,34 @@ class S3Server {
vault, vault,
}, },
}; };
// Start a new span for the request
const tracer = trace.getTracer(process.env.OTEL_SERVICE_NAME || 'S3-cloudserver');
const span = tracer.startSpan('s3-service-request', {
kind: 1, // SERVER
attributes: { 'http.method': req.method, 'http.url': req.url },
});
context.with(trace.setSpan(context.active(), span), () => {
// ----- Add nested spans and events -----
const activeSpan = trace.getSpan(context.active());
activeSpan.addEvent('inside routeRequest');
const v4Span = tracer.startSpan('verifySignatureV4', {
kind: 1, // SERVER
attributes: { 'verify.step': 'start' },
});
context.with(trace.setSpan(context.active(), v4Span), () => {
// Simulate verifySignatureV4 process
setTimeout(() => {
v4Span.end(); // End the nested span
activeSpan.addEvent('verifySignatureV4 completed');
routes(req, res, params, logger, _config); routes(req, res, params, logger, _config);
span.end(); // End the main span when the request handling is complete
}, 100); // Simulate some delay in the verification process
});
// -----
});
} }
/** /**

View File

@ -20,6 +20,10 @@
"homepage": "https://github.com/scality/S3#readme", "homepage": "https://github.com/scality/S3#readme",
"dependencies": { "dependencies": {
"@hapi/joi": "^17.1.0", "@hapi/joi": "^17.1.0",
"@honeycombio/opentelemetry-node": "^0.7.2",
"@opentelemetry/api": "^1.8.0",
"@opentelemetry/auto-instrumentations-node": "^0.46.1",
"@opentelemetry/instrumentation-aws-sdk": "^0.41.0",
"arsenal": "git+https://github.com/scality/arsenal#7.70.29", "arsenal": "git+https://github.com/scality/arsenal#7.70.29",
"async": "~2.5.0", "async": "~2.5.0",
"aws-sdk": "2.905.0", "aws-sdk": "2.905.0",
@ -84,7 +88,7 @@
"start": "npm-run-all --parallel start_dmd start_s3server", "start": "npm-run-all --parallel start_dmd start_s3server",
"start_mdserver": "node mdserver.js", "start_mdserver": "node mdserver.js",
"start_dataserver": "node dataserver.js", "start_dataserver": "node dataserver.js",
"start_s3server": "node index.js", "start_s3server": "node -r ./tracing.js index.js",
"start_dmd": "npm-run-all --parallel start_mdserver start_dataserver", "start_dmd": "npm-run-all --parallel start_mdserver start_dataserver",
"start_utapi": "node lib/utapi/utapi.js", "start_utapi": "node lib/utapi/utapi.js",
"utapi_replay": "node lib/utapi/utapiReplay.js", "utapi_replay": "node lib/utapi/utapiReplay.js",

25
tracing.js Normal file
View File

@ -0,0 +1,25 @@
// Example filename: tracing.js
'use strict';
const { HoneycombSDK } = require('@honeycombio/opentelemetry-node');
const {
getNodeAutoInstrumentations,
} = require('@opentelemetry/auto-instrumentations-node');
const { IORedisInstrumentation } = require('@opentelemetry/instrumentation-ioredis');
// Uses environment variables named HONEYCOMB_API_KEY and OTEL_SERVICE_NAME
const sdk = new HoneycombSDK({
instrumentations: [getNodeAutoInstrumentations({
// We recommend disabling fs automatic instrumentation because
// it can be noisy and expensive during startup
'@opentelemetry/instrumentation-fs': {
enabled: false,
},
}),
new IORedisInstrumentation(),
],
});
sdk.start();

1594
yarn.lock

File diff suppressed because it is too large Load Diff