Skip to content

Commit 65d17d4

Browse files
authored
Merge branch 'main' into sqs-batch-receive
2 parents 19e5cdd + 0baef34 commit 65d17d4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+2431
-688
lines changed

examples/meta-node/.eslintrc.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
'use strict';
18+
19+
const baseConfig = require('../../eslint.config');
20+
21+
module.exports = {
22+
...baseConfig,
23+
env: {
24+
node: true,
25+
},
26+
};

examples/meta-node/.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package-lock=false

examples/meta-node/client.js

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
117
'use strict';
218

319
// eslint-disable-next-line import/order
@@ -19,8 +35,12 @@ function makeRequest() {
1935
span.setStatus({ code: api.SpanStatusCode.ERROR, message: e.message });
2036
}
2137
span.end();
22-
console.log('Sleeping 5 seconds before shutdown to ensure all records are flushed.');
23-
setTimeout(() => { console.log('Completed.'); }, 5000);
38+
console.log(
39+
'Sleeping 5 seconds before shutdown to ensure all records are flushed.'
40+
);
41+
setTimeout(() => {
42+
console.log('Completed.');
43+
}, 5000);
2444
});
2545
}
2646

examples/meta-node/package.json

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
"description": "Example of using meta package for default auto instrumentations in node",
66
"main": "index.js",
77
"scripts": {
8-
"lint": "eslint . --ext .js",
9-
"lint:fix": "eslint . --ext .js --fix",
8+
"lint": "eslint . --ext=ts,js,mjs",
9+
"lint:fix": "eslint . --ext=ts,js,mjs --fix",
1010
"zipkin:server": "cross-env EXPORTER=zipkin node ./server.js",
1111
"zipkin:client": "cross-env EXPORTER=zipkin node ./client.js"
1212
},
@@ -31,8 +31,7 @@
3131
},
3232
"homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib#readme",
3333
"devDependencies": {
34-
"cross-env": "^6.0.0",
35-
"eslint": "^7.4.0"
34+
"cross-env": "^6.0.0"
3635
},
3736
"dependencies": {
3837
"@opentelemetry/api": "^1.0.2",

examples/meta-node/server.js

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
117
'use strict';
218

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

3753
app.get('/run_test', async (req, res) => {
38-
const createdCat = await axios.post(`http://localhost:${PORT}/cats`, {
39-
name: 'Tom',
40-
friends: [
41-
'Jerry',
42-
],
43-
}, {
44-
headers: {
45-
Authorization: 'secret_token',
54+
const createdCat = await axios.post(
55+
`http://localhost:${PORT}/cats`,
56+
{
57+
name: 'Tom',
58+
friends: ['Jerry'],
4659
},
47-
});
60+
{
61+
headers: {
62+
Authorization: 'secret_token',
63+
},
64+
}
65+
);
4866

4967
return res.status(201).send(createdCat.data);
5068
});

examples/meta-node/tracer.js

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,31 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
117
'use strict';
218

319
const {
4-
diag, trace, DiagConsoleLogger, DiagLogLevel,
20+
diag,
21+
trace,
22+
DiagConsoleLogger,
23+
DiagLogLevel,
524
} = require('@opentelemetry/api');
625
const { NodeTracerProvider } = require('@opentelemetry/sdk-trace-node');
7-
const { getNodeAutoInstrumentations } = require('@opentelemetry/auto-instrumentations-node');
26+
const {
27+
getNodeAutoInstrumentations,
28+
} = require('@opentelemetry/auto-instrumentations-node');
829
const { CollectorTraceExporter } = require('@opentelemetry/exporter-collector');
930
const { SimpleSpanProcessor } = require('@opentelemetry/sdk-trace-base');
1031
const { registerInstrumentations } = require('@opentelemetry/instrumentation');
@@ -18,17 +39,15 @@ module.exports = () => {
1839
});
1940

2041
const provider = new NodeTracerProvider({
21-
spanProcessors: [
22-
new SimpleSpanProcessor(exporter),
23-
],
42+
spanProcessors: [new SimpleSpanProcessor(exporter)],
2443
});
2544
provider.register();
2645

2746
registerInstrumentations({
2847
instrumentations: [
2948
getNodeAutoInstrumentations({
3049
'@opentelemetry/instrumentation-http': {
31-
applyCustomAttributesOnSpan: (span) => {
50+
applyCustomAttributesOnSpan: span => {
3251
span.setAttribute('foo2', 'bar2');
3352
},
3453
},

examples/mongodb/.eslintrc.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
'use strict';
18+
19+
const baseConfig = require('../../eslint.config');
20+
21+
module.exports = {
22+
...baseConfig,
23+
env: {
24+
node: true,
25+
},
26+
};

examples/mongodb/package.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
"description": "Example of mongodb integration with OpenTelemetry",
66
"main": "index.js",
77
"scripts": {
8+
"lint": "eslint . --ext=ts,js,mjs",
9+
"lint:fix": "eslint . --ext=ts,js,mjs --fix",
810
"docker:start": "docker run -e MONGODB_DB=opentelemetry-tests -e MONGODB_PORT=27017 -e MONGODB_HOST=127.0.0.1 -p 27017:27017 --rm mongo",
911
"zipkin:server": "cross-env EXPORTER=zipkin ts-node src/server.ts",
1012
"zipkin:client": "cross-env EXPORTER=zipkin ts-node src/client.ts",
@@ -35,6 +37,8 @@
3537
"@opentelemetry/instrumentation": "^0.54.2",
3638
"@opentelemetry/instrumentation-http": "^0.54.2",
3739
"@opentelemetry/instrumentation-mongodb": "^0.48.0",
40+
"@opentelemetry/exporter-trace-otlp-http": "^0.54.2",
41+
"@opentelemetry/resources": "^1.27.0",
3842
"@opentelemetry/sdk-trace-node": "^1.27.0",
3943
"@opentelemetry/sdk-trace-base": "^1.27.0",
4044
"@opentelemetry/semantic-conventions": "^1.27.0",

examples/mongodb/src/client.ts

Lines changed: 73 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,25 @@
1-
'use strict';
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
216

3-
import * as api from '@opentelemetry/api';
4-
import { setupTracing } from './tracer';
5-
6-
const tracer = setupTracing('example-mongodb-http-client')
17+
import * as api from '@opentelemetry/api';
718
import * as http from 'http';
19+
// eslint-disable-next-line import/extensions
20+
import { setupTracing } from './tracer';
821

22+
const tracer = setupTracing('example-mongodb-http-client');
923

1024
/** A function which makes requests and handles response. */
1125
function makeRequest() {
@@ -19,58 +33,71 @@ function makeRequest() {
1933

2034
api.context.with(api.trace.setSpan(api.ROOT_CONTEXT, span), () => {
2135
queries += 1;
22-
http.get({
23-
host: 'localhost',
24-
port: 8080,
25-
path: '/collection/',
26-
}, (response) => {
27-
const body: any = [];
28-
response.on('data', (chunk) => body.push(chunk));
29-
response.on('end', () => {
30-
responses += 1;
31-
console.log(body.toString());
32-
if (responses === queries) span.end();
33-
});
34-
});
36+
http.get(
37+
{
38+
host: 'localhost',
39+
port: 8080,
40+
path: '/collection/',
41+
},
42+
response => {
43+
const body: any = [];
44+
response.on('data', chunk => body.push(chunk));
45+
response.on('end', () => {
46+
responses += 1;
47+
console.log(body.toString());
48+
if (responses === queries) span.end();
49+
});
50+
}
51+
);
3552
});
3653
api.context.with(api.trace.setSpan(api.ROOT_CONTEXT, span), () => {
3754
queries += 1;
38-
http.get({
39-
host: 'localhost',
40-
port: 8080,
41-
path: '/insert/',
42-
}, (response) => {
43-
const body: any = [];
44-
response.on('data', (chunk) => body.push(chunk));
45-
response.on('end', () => {
46-
responses += 1;
47-
console.log(body.toString());
48-
if (responses === queries) span.end();
49-
});
50-
});
55+
http.get(
56+
{
57+
host: 'localhost',
58+
port: 8080,
59+
path: '/insert/',
60+
},
61+
response => {
62+
const body: any = [];
63+
response.on('data', chunk => body.push(chunk));
64+
response.on('end', () => {
65+
responses += 1;
66+
console.log(body.toString());
67+
if (responses === queries) span.end();
68+
});
69+
}
70+
);
5171
});
5272
api.context.with(api.trace.setSpan(api.ROOT_CONTEXT, span), () => {
5373
queries += 1;
54-
http.get({
55-
host: 'localhost',
56-
port: 8080,
57-
path: '/get/',
58-
}, (response) => {
59-
const body: any = [];
60-
response.on('data', (chunk) => body.push(chunk));
61-
response.on('end', () => {
62-
responses += 1;
63-
console.log(body.toString());
64-
if (responses === queries) span.end();
65-
});
66-
});
74+
http.get(
75+
{
76+
host: 'localhost',
77+
port: 8080,
78+
path: '/get/',
79+
},
80+
response => {
81+
const body: any = [];
82+
response.on('data', chunk => body.push(chunk));
83+
response.on('end', () => {
84+
responses += 1;
85+
console.log(body.toString());
86+
if (responses === queries) span.end();
87+
});
88+
}
89+
);
6790
});
6891

6992
// The process must live for at least the interval past any traces that
7093
// must be exported, or some risk being lost if they are recorded after the
7194
// last export.
72-
console.log('Sleeping 5 seconds before shutdown to ensure all records are flushed.');
73-
setTimeout(() => { console.log('Completed.'); }, 5000);
95+
console.log(
96+
'Sleeping 5 seconds before shutdown to ensure all records are flushed.'
97+
);
98+
setTimeout(() => {
99+
console.log('Completed.');
100+
}, 5000);
74101
}
75102

76103
makeRequest();

0 commit comments

Comments
 (0)