Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions examples/meta-node/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright The OpenTelemetry Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

const baseConfig = require('../../eslint.config');

module.exports = {
...baseConfig,
env: {
node: true,
},
};
1 change: 1 addition & 0 deletions examples/meta-node/.npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package-lock=false
24 changes: 22 additions & 2 deletions examples/meta-node/client.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright The OpenTelemetry Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

// eslint-disable-next-line import/order
Expand All @@ -19,8 +35,12 @@ function makeRequest() {
span.setStatus({ code: api.SpanStatusCode.ERROR, message: e.message });
}
span.end();
console.log('Sleeping 5 seconds before shutdown to ensure all records are flushed.');
setTimeout(() => { console.log('Completed.'); }, 5000);
console.log(
'Sleeping 5 seconds before shutdown to ensure all records are flushed.'
);
setTimeout(() => {
console.log('Completed.');
}, 5000);
});
}

Expand Down
7 changes: 3 additions & 4 deletions examples/meta-node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"description": "Example of using meta package for default auto instrumentations in node",
"main": "index.js",
"scripts": {
"lint": "eslint . --ext .js",
"lint:fix": "eslint . --ext .js --fix",
"lint": "eslint . --ext=ts,js,mjs",
"lint:fix": "eslint . --ext=ts,js,mjs --fix",
"zipkin:server": "cross-env EXPORTER=zipkin node ./server.js",
"zipkin:client": "cross-env EXPORTER=zipkin node ./client.js"
},
Expand All @@ -31,8 +31,7 @@
},
"homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib#readme",
"devDependencies": {
"cross-env": "^6.0.0",
"eslint": "^7.4.0"
"cross-env": "^6.0.0"
},
"dependencies": {
"@opentelemetry/api": "^1.0.2",
Expand Down
36 changes: 27 additions & 9 deletions examples/meta-node/server.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright The OpenTelemetry Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

// eslint-disable-next-line
Expand Down Expand Up @@ -35,16 +51,18 @@ async function setupRoutes() {
app.use(express.json());

app.get('/run_test', async (req, res) => {
const createdCat = await axios.post(`http://localhost:${PORT}/cats`, {
name: 'Tom',
friends: [
'Jerry',
],
}, {
headers: {
Authorization: 'secret_token',
const createdCat = await axios.post(
`http://localhost:${PORT}/cats`,
{
name: 'Tom',
friends: ['Jerry'],
},
});
{
headers: {
Authorization: 'secret_token',
},
}
);

return res.status(201).send(createdCat.data);
});
Expand Down
31 changes: 25 additions & 6 deletions examples/meta-node/tracer.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,31 @@
/*
* Copyright The OpenTelemetry Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

'use strict';

const {
diag, trace, DiagConsoleLogger, DiagLogLevel,
diag,
trace,
DiagConsoleLogger,
DiagLogLevel,
} = require('@opentelemetry/api');
const { NodeTracerProvider } = require('@opentelemetry/sdk-trace-node');
const { getNodeAutoInstrumentations } = require('@opentelemetry/auto-instrumentations-node');
const {
getNodeAutoInstrumentations,
} = require('@opentelemetry/auto-instrumentations-node');
const { CollectorTraceExporter } = require('@opentelemetry/exporter-collector');
const { SimpleSpanProcessor } = require('@opentelemetry/sdk-trace-base');
const { registerInstrumentations } = require('@opentelemetry/instrumentation');
Expand All @@ -18,17 +39,15 @@ module.exports = () => {
});

const provider = new NodeTracerProvider({
spanProcessors: [
new SimpleSpanProcessor(exporter),
],
spanProcessors: [new SimpleSpanProcessor(exporter)],
});
provider.register();

registerInstrumentations({
instrumentations: [
getNodeAutoInstrumentations({
'@opentelemetry/instrumentation-http': {
applyCustomAttributesOnSpan: (span) => {
applyCustomAttributesOnSpan: span => {
span.setAttribute('foo2', 'bar2');
},
},
Expand Down