diff --git a/detectors/node/opentelemetry-resource-detector-gcp/test/fixtures/use-gcp-detector.js b/detectors/node/opentelemetry-resource-detector-gcp/test/fixtures/use-gcp-detector.js index cdfd6e7bb8..0c71a081f6 100644 --- a/detectors/node/opentelemetry-resource-detector-gcp/test/fixtures/use-gcp-detector.js +++ b/detectors/node/opentelemetry-resource-detector-gcp/test/fixtures/use-gcp-detector.js @@ -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({ @@ -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); }); @@ -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