Skip to content

Commit a170e11

Browse files
committed
lib: add nsolidTracer EventEmitter
So we can subscribe to the `flagsUpdated` event to receive notifications when the tracing flags have changed. Use it in the otel/core.js:register() method. PR-URL: #216 Reviewed-By: Rafael Gonzaga <[email protected]> PR-URL: #245
1 parent a086f90 commit a170e11

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

lib/internal/nsolid_trace.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ const {
66
RegExp,
77
} = primordials;
88

9+
const EventEmitter = require('events');
10+
const binding = internalBinding('nsolid_api');
911
const { nsolidApi } = require('internal/async_hooks');
1012

1113
const {
@@ -66,7 +68,14 @@ function extractSpanContextFromHttpHeaders(context, headers) {
6668
return getApi().trace.setSpanContext(context, spanContext);
6769
}
6870

71+
const nsolidTracer = new EventEmitter();
72+
binding.setToggleTracingFn(() => {
73+
nsolidTracer.emit('flagsUpdated');
74+
});
75+
76+
6977
module.exports = {
7078
extractSpanContextFromHttpHeaders,
7179
generateSpan,
80+
nsolidTracer,
7281
};

lib/internal/otel/core.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@ function register(api) {
2626
// TODO(santigimeno): perform some kind of validation that the api is actually
2727
// the OTEL api.
2828
api_ = api;
29-
binding.setToggleTracingFn((enable) => {
30-
if (enable) {
29+
const { nsolidTracer } = require('internal/nsolid_trace');
30+
nsolidTracer.on('flagsUpdated', () => {
31+
if (binding.trace_flags[0]) {
3132
enableApi();
3233
} else {
3334
disableApi();

0 commit comments

Comments
 (0)