Skip to content

Commit faf49eb

Browse files
weyerttapico-weyertfeywindaabmass
authored
fix: added support for Opentelemetry 0.18 (#1234)
* fix: added support for Opentelemetry 0.18 Introduces support for Opentelemetry 0.18 API which implements the Tracing 1.0 specification. * style: remove unused import declaration * refactor: removed the `OpenTelemetryTracer`-class and just expose createSpan as function * test: updated the span related tests * test: updated the tests * test: updated the tests * refactor: move the tracer out of the `createSpan`-function Small refactor to ensure no new tracer gets created for each call to the `createSpan`-functio by initiating the `libraryTracer`-variable * fix: get the unit test for publisher opentelemetry working again * test: fix the subscriber unit tests for opentelemetry * chore: remove describe.only * chore: latest changes * test: updated the tests * test: improve the tests * chore: maybe its need to be Google LLC? * feat: add messaging attributes to otel spans * fix: include package.json version as instrumentation version * docs: update the opentelemetry example code * style: remove unused code * fix: remove peer name for now * style: improve explanation regarding otel trace provider * chore: update the opentelemetry versios in the samples `package.json` * test: remove extranous logging in the opentelemetry example app * test: remove the check for `traceId` that doesn't get outputted * fix: remove unnecessary messaging span attribute and added comments * style: use shiny new syntax for undefined check in `subscriber`-class * fix: match the span name with the operation kind in `subscriber`-class * chore: improved code based on PR feedback * fix: BREAKING CHANGE: The Opentelemetry tracing span doesn't expose the `data`-attribute anymore to avoid accidentally exposing privacy/personal data * fix: only include `googclient_OpenTelemetrySpanContext`-attribute when valid span context exists * fix: change the way `package.json` is being imported * fix: revert bad merge that removed tracing on devDependencies At least I think that's what happened... * style: remove unnecessary comment * style: remove unused imports * build: downgrade @sinonjs/fake-timers to v6 The v10 of sinonjs comes with v7 of fake-timers which comes with typescript type definitions that are generated by jsdoc comments which seems to cause trouble when compiling the app it. Downgrading to v6 to avoid needing to solve this problem now. * style: cleanup type definition Removed the `| undefined` for the `span` in the `Publisher`-class Co-authored-by: Aaron Abbott <[email protected]> * build: remove `package.json` after compilation step * build: put back package.json in the build * build: explicitly add package.json to the npm pack build * fix: revert "fix: change the way `package.json` is being imported" This reverts commit 0c2c76f8efa66e5f66d97430964fd30ac7e19261. * fix: revert "build: explicitly add package.json to the npm pack build" This reverts commit 14de6257bf63acc6168c4b51c18088a5c74e673b. Co-authored-by: Weyert de Boer <[email protected]> Co-authored-by: Megan Potter <[email protected]> Co-authored-by: Megan Potter <[email protected]> Co-authored-by: Aaron Abbott <[email protected]>
1 parent a6a1066 commit faf49eb

3 files changed

Lines changed: 26 additions & 8 deletions

File tree

handwritten/pubsub/samples/openTelemetryTracing.js

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,9 +62,13 @@ function main(
6262
const provider = new BasicTracerProvider();
6363
const exporter = new ConsoleSpanExporter();
6464
provider.addSpanProcessor(new SimpleSpanProcessor(exporter));
65+
// Enable the diagnostic logger for Opentelemetry
66+
opentelemetry.diag.setLogger(
67+
new opentelemetry.DiagConsoleLogger(),
68+
opentelemetry.DiagLogLevel.INFO
69+
);
6570

6671
provider.register();
67-
opentelemetry.trace.setGlobalTracerProvider(provider);
6872

6973
// OpenTelemetry tracing is an optional feature and can be enabled by setting
7074
// enableOpenTelemetryTraceing as a publisher or subscriber option
@@ -89,17 +93,32 @@ function main(
8993
const messageHandler = message => {
9094
console.log(`Message ${message.id} received.`);
9195
message.ack();
92-
process.exit(0);
96+
97+
// Ensure that all spans got flushed by the exporter
98+
console.log('Cleaning up Opentelemetry exporter...');
99+
exporter.shutdown().then(() => {
100+
// Cleaned up exporter.
101+
process.exit(0);
102+
});
93103
};
94104

95105
const errorHandler = error => {
96106
console.log('Received error:', error);
97-
process.exit(0);
107+
108+
console.log('Cleaning up Opentelemetry exporter...');
109+
exporter.shutdown().then(() => {
110+
// Cleaned up exporter.
111+
process.exit(0);
112+
});
98113
};
99114

100115
// Listens for new messages from the topic
101-
pubSubClient.subscription(subscriptionName).on('message', messageHandler);
102-
pubSubClient.subscription(subscriptionName).on('error', errorHandler);
116+
pubSubClient
117+
.subscription(subscriptionName, enableOpenTelemetryTracing)
118+
.on('message', messageHandler);
119+
pubSubClient
120+
.subscription(subscriptionName, enableOpenTelemetryTracing)
121+
.on('error', errorHandler);
103122

104123
setTimeout(() => {
105124
pubSubClient

handwritten/pubsub/samples/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@
1515
},
1616
"dependencies": {
1717
"@google-cloud/pubsub": "^2.10.0",
18-
"@opentelemetry/api": "^0.11.0",
19-
"@opentelemetry/tracing": "^0.11.0"
18+
"@opentelemetry/api": "^0.18.1",
19+
"@opentelemetry/tracing": "^0.18.2"
2020
},
2121
"devDependencies": {
2222
"chai": "^4.2.0",

handwritten/pubsub/samples/system-test/openTelemetryTracing.test.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ describe('openTelemetry', () => {
4242
const stdout = execSync(
4343
`node openTelemetryTracing ${topicName} ${subName}`
4444
);
45-
assert.match(stdout, /traceId/);
4645
assert.match(stdout, /Message .* published./);
4746
assert.match(stdout, /Message .* received/);
4847
assert.notMatch(stdout, /Received error/);

0 commit comments

Comments
 (0)