-
Notifications
You must be signed in to change notification settings - Fork 156
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Image Render: Support Tracing #586
base: master
Are you sure you want to change the base?
Conversation
@@ -45,6 +46,8 @@ export class ConsoleLogger implements Logger { | |||
transports.push(new winston.transports.Console(options)); | |||
} | |||
|
|||
//@opentelemetry/instrumentation-winston auto inject trace-context into Winston log records | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Confirm this is the case in the log output in terminal. You can check that trace_id
, span_id
, and trace_flags
is included
src/tracing.ts
Outdated
@@ -0,0 +1,41 @@ | |||
import {NodeSDK} from '@opentelemetry/sdk-node'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I followed OpenTelemetry Doc for Node.js to implement this
src/tracing.ts
Outdated
instrumentations: [ | ||
getNodeAutoInstrumentations({ | ||
// only instrument fs if it is part of another trace | ||
'@opentelemetry/instrumentation-fs': { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the fs module is very noisy. It create 10+ traces with singular span so it did not make much sense to have it unless it's part of another trace.
There is a list of supported autoinstrumentation. We can opt out of any in the future we do not care to trace those libraries
src/tracing.ts
Outdated
export function startTracing(log: Logger) { | ||
sdk.start(); | ||
log.info('Starting tracing'); | ||
|
||
process.on('SIGTERM', () => { | ||
sdk.shutdown() | ||
.then(() => log.debug('Tracing terminated')) | ||
.catch((error) => log.error('Error terminating tracing', error)) | ||
.finally(() => process.exit(0)); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Create startTracing separately from the rest of initialization steps b/c we want to only capture traces if it's enabled
@@ -1,3 +1,4 @@ | |||
import { startTracing } from './tracing'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OpenTelemetry needs to be initialized before the other modules (express, http, winston, etc) in order for it to auto capture telemetry trace data from those libraries so it must come first
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good! I tested it and this worked. However, I don't find the current traces very useful as there is a big blank gap in the middle.
An easy place to add some manual spans would be in the withTimingMetrics
function. Something like that but adding some config checks:
async withTimingMetrics<T>(step: string, callback: () => Promise<T>): Promise<T> {
if (this.config.timingMetrics) {
const endTimer = this.metrics.durationHistogram.startTimer({ step });
const res = this.tracer.startActiveSpan(step, async (span) => {
const cbRes = await callback();
span.end();
return cbRes;
});
endTimer();
return res;
} else {
return callback();
}
}
The Browser class could initialize its tracer in its constructor (this should work for all browser implementations, e.g. with mode: "clustered"
):
export class Browser {
tracer: Tracer;
constructor(protected config: RenderingConfig, protected log: Logger, protected metrics: Metrics) {
this.log.debug('Browser initialized', 'config', this.config);
this.tracer = trace.getTracer('browser');
}
...
Also, I looked into what is missing to have a link between Grafana traces and image renderer traces and this simple change is working (to enable traces in Grafana, you need to set:
[tracing.opentelemetry.otlp]
# otlp destination (ex localhost:4317)
address = localhost:4317
). I will test it out a bit more and check if this need to be initialized only when tracing is enabled or if this is a no-op when tracing is disabled.
src/tracing.ts
Outdated
@@ -0,0 +1,41 @@ | |||
import {NodeSDK} from '@opentelemetry/sdk-node'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This whole file should be formatted using Prettier linter (we don't have a check for that in CI but we should do our best).
Co-authored-by: Agnès Toulet <[email protected]>
@AgnesToulet setting this address is enable traces in Grafana in dev env right? Traces should already be enabled in Cloud via Faro |
Yes it's for your local environment. It's enabled by default on Cloud (Faro is for frontend monitoring, its configuration is in a different section of the ini file, I don't think both are related). |
Testing Instructons:
Local Setup:
OTEL_EXPORTER_OTLP_TRACES_ENDPOINT="http://localhost:4318/v1/traces" node build/app.js server --port=8081 --config=dev.json
to set env varDeployment_tools pr for adding env vars