Skip to content

Commit

Permalink
chore(detector-gpc): add missing license header
Browse files Browse the repository at this point in the history
  • Loading branch information
david-luna committed Jul 10, 2024
1 parent 1dbe92f commit 0aaaf29
Showing 1 changed file with 48 additions and 29 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,25 @@
const { createTestNodeSdk } = require ('@opentelemetry/contrib-test-utils');
const { HttpInstrumentation } = require ('@opentelemetry/instrumentation-http');
const { gcpDetector } = require ('../../build/src/index.js');
/*
* 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.
*/

// Usage:
// node use-gcp-detector.js

const { createTestNodeSdk } = require('@opentelemetry/contrib-test-utils');
const { HttpInstrumentation } = require('@opentelemetry/instrumentation-http');
const { gcpDetector } = require('../../build/src/index.js');


const sdk = createTestNodeSdk({
Expand All @@ -9,21 +28,21 @@ const sdk = createTestNodeSdk({
new HttpInstrumentation(),
],
resourceDetectors: [gcpDetector],
});
});

sdk.start();

const http = require('http');

const server = http.createServer((req,res) => {
const server = http.createServer((req, res) => {
console.log('incoming request: %s %s %s', req.method, req.url, req.headers);

req.resume();
req.on('end', function () {
const body = 'pong';
res.writeHead(200, {
'content-type': 'text/plain',
'content-length': body.length,
'content-type': 'text/plain',
'content-length': body.length,
});
res.end(body);
});
Expand All @@ -35,27 +54,27 @@ server.listen(0, '127.0.0.1', async function () {
// First request to show a client error.
const startTime = Date.now();
await new Promise((resolve) => {
const clientReq = http.request(
`http://127.0.0.1:${port}/ping`,
function (cres) {
console.log(
'client response: %s %s',
cres.statusCode,
cres.headers
);
const chunks = [];
cres.on('data', function (chunk) {
chunks.push(chunk);
});
cres.on('end', function () {
const body = chunks.join('');
console.log('client response body: %j', body);
resolve();
});
}
);
clientReq.write('ping');
clientReq.end();
const clientReq = http.request(
`http://127.0.0.1:${port}/ping`,
function (cres) {
console.log(
'client response: %s %s',
cres.statusCode,
cres.headers
);
const chunks = [];
cres.on('data', function (chunk) {
chunks.push(chunk);
});
cres.on('end', function () {
const body = chunks.join('');
console.log('client response body: %j', body);
resolve();
});
}
);
clientReq.write('ping');
clientReq.end();
});

// flush any left spans
Expand Down

0 comments on commit 0aaaf29

Please sign in to comment.