@opentelemetry/resource-detector-instana 0.20.0 → 0.22.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -38,7 +38,7 @@ sdk.start()
38
38
 
39
39
  ## Available detectors
40
40
 
41
- This package uses `@opentelemetry/semantic-conventions` version `1.22+`, which implements Semantic Convention [Version 1.7.0](https://github.com/open-telemetry/opentelemetry-specification/blob/v1.7.0/semantic_conventions/README.md)
41
+ This package implements Semantic Convention v1.33.1.
42
42
 
43
43
  ### Instana Agent Detector
44
44
 
@@ -15,17 +15,14 @@
15
15
  */
16
16
  import { context, diag } from '@opentelemetry/api';
17
17
  import { suppressTracing } from '@opentelemetry/core';
18
- import { SEMRESATTRS_PROCESS_PID, SEMRESATTRS_SERVICE_INSTANCE_ID, } from '@opentelemetry/semantic-conventions';
18
+ import { ATTR_PROCESS_PID, ATTR_SERVICE_INSTANCE_ID } from '../semconv';
19
19
  import * as http from 'http';
20
20
  class InstanaAgentDetector {
21
21
  INSTANA_AGENT_DEFAULT_HOST = 'localhost';
22
22
  INSTANA_AGENT_DEFAULT_PORT = 42699;
23
23
  detect() {
24
24
  const dataPromise = context.with(suppressTracing(context.active()), () => this._gatherData());
25
- const attrNames = [
26
- SEMRESATTRS_PROCESS_PID,
27
- SEMRESATTRS_SERVICE_INSTANCE_ID,
28
- ];
25
+ const attrNames = [ATTR_PROCESS_PID, ATTR_SERVICE_INSTANCE_ID];
29
26
  const attributes = {};
30
27
  attrNames.forEach(name => {
31
28
  // Each resource attribute is determined asynchronously in _gatherData().
@@ -39,8 +36,8 @@ class InstanaAgentDetector {
39
36
  try {
40
37
  const data = await this._retryHandler(host, port, 0);
41
38
  return {
42
- [SEMRESATTRS_PROCESS_PID]: data.pid,
43
- [SEMRESATTRS_SERVICE_INSTANCE_ID]: data.agentUuid,
39
+ [ATTR_PROCESS_PID]: data.pid,
40
+ [ATTR_SERVICE_INSTANCE_ID]: data.agentUuid,
44
41
  };
45
42
  }
46
43
  catch {
@@ -1 +1 @@
1
- {"version":3,"file":"InstanaAgentDetector.js","sourceRoot":"","sources":["../../../src/detectors/InstanaAgentDetector.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAMtD,OAAO,EACL,uBAAuB,EACvB,+BAA+B,GAChC,MAAM,qCAAqC,CAAC;AAC7C,OAAO,KAAK,IAAI,MAAM,MAAM,CAAC;AAE7B,MAAM,oBAAoB;IACf,0BAA0B,GAAG,WAAW,CAAC;IACzC,0BAA0B,GAAG,KAAK,CAAC;IAE5C,MAAM;QACJ,MAAM,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,MAAM,EAAE,CAAC,EAAE,GAAG,EAAE,CACvE,IAAI,CAAC,WAAW,EAAE,CACnB,CAAC;QAEF,MAAM,SAAS,GAAG;YAChB,uBAAuB;YACvB,+BAA+B;SAChC,CAAC;QAEF,MAAM,UAAU,GAAG,EAAgC,CAAC;QACpD,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;YACvB,yEAAyE;YACzE,UAAU,CAAC,IAAI,CAAC,GAAG,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;QAC1D,CAAC,CAAC,CAAC;QAEH,OAAO,EAAE,UAAU,EAAE,CAAC;IACxB,CAAC;IAEO,KAAK,CAAC,WAAW;QACvB,MAAM,IAAI,GACR,OAAO,CAAC,GAAG,CAAC,kBAAkB,IAAI,IAAI,CAAC,0BAA0B,CAAC;QACpE,MAAM,IAAI,GAAG,MAAM,CACjB,OAAO,CAAC,GAAG,CAAC,kBAAkB,IAAI,IAAI,CAAC,0BAA0B,CAClE,CAAC;QAEF,IAAI;YACF,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AAI;wBACF,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;wBACjC,IAAI,IAAI,CAAC,GAAG,IAAI,IAAI,CAAC,SAAS,EAAE;4BAC9B,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC;yBACtB;wBAED,MAAM,CACJ,IAAI,KAAK,CAAC,0CAA0C,IAAI,GAAG,CAAC,CAC7D,CAAC;qBACH;oBAAC,OAAO,CAAC,EAAE;wBACV,MAAM,CAAC,CAAC,CAAC,CAAC;qBACX;gBACH,CAAC,CAAC,CAAC;YACL,CAAC,CAAC,CAAC;YAEH,GAAG,CAAC,EAAE,CAAC,SAAS,EAAE,GAAG,EAAE,CACrB,MAAM,CAAC,IAAI,KAAK,CAAC,kCAAkC,CAAC,CAAC,CACtD,CAAC;YACF,GAAG,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,CAAC,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;YAEpC,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC,CAAC;YAC3C,GAAG,CAAC,GAAG,EAAE,CAAC;QACZ,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AAED,MAAM,CAAC,MAAM,oBAAoB,GAAG,IAAI,oBAAoB,EAAE,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { context, diag } from '@opentelemetry/api';\nimport { suppressTracing } from '@opentelemetry/core';\nimport {\n ResourceDetector,\n DetectedResource,\n DetectedResourceAttributes,\n} from '@opentelemetry/resources';\nimport {\n SEMRESATTRS_PROCESS_PID,\n SEMRESATTRS_SERVICE_INSTANCE_ID,\n} from '@opentelemetry/semantic-conventions';\nimport * as http from 'http';\n\nclass InstanaAgentDetector implements ResourceDetector {\n readonly INSTANA_AGENT_DEFAULT_HOST = 'localhost';\n readonly INSTANA_AGENT_DEFAULT_PORT = 42699;\n\n detect(): DetectedResource {\n const dataPromise = context.with(suppressTracing(context.active()), () =>\n this._gatherData()\n );\n\n const attrNames = [\n SEMRESATTRS_PROCESS_PID,\n SEMRESATTRS_SERVICE_INSTANCE_ID,\n ];\n\n const attributes = {} as DetectedResourceAttributes;\n attrNames.forEach(name => {\n // Each resource attribute is determined asynchronously in _gatherData().\n attributes[name] = dataPromise.then(data => data[name]);\n });\n\n return { attributes };\n }\n\n private async _gatherData(): Promise<DetectedResourceAttributes> {\n const host =\n process.env.INSTANA_AGENT_HOST || this.INSTANA_AGENT_DEFAULT_HOST;\n const port = Number(\n process.env.INSTANA_AGENT_PORT || this.INSTANA_AGENT_DEFAULT_PORT\n );\n\n try {\n const data = await this._retryHandler(host, port, 0);\n\n return {\n [SEMRESATTRS_PROCESS_PID]: data.pid,\n [SEMRESATTRS_SERVICE_INSTANCE_ID]: data.agentUuid,\n };\n } catch {\n return {};\n }\n }\n\n private timeout(ms: number) {\n return new Promise(resolve => setTimeout(resolve, ms).unref());\n }\n\n private async _retryHandler(\n host: string,\n port: number,\n tries: number\n ): Promise<{ pid: number; agentUuid: string }> {\n const MAX_TRIES = 3;\n\n try {\n return await this._fetchAgentData(host, port);\n } catch (err) {\n if (tries < MAX_TRIES) {\n diag.debug(\n `Retrying to connect to the Instana agent on ${host}:${port}....`\n );\n\n const retryTimeout = process.env.INSTANA_RETRY_TIMEOUT_MS\n ? Number(process.env.INSTANA_RETRY_TIMEOUT_MS)\n : 1000;\n\n await this.timeout(retryTimeout);\n return await this._retryHandler(host, port, tries + 1);\n }\n\n throw err;\n }\n }\n\n private async _fetchAgentData(\n host: string,\n port: number\n ): Promise<{ pid: number; agentUuid: string }> {\n const agentTimeoutMs = process.env.INSTANA_AGENT_TIMEOUT_MS\n ? Number(process.env.INSTANA_AGENT_TIMEOUT_MS)\n : 3 * 1000;\n\n const payload = {\n pid: process.pid,\n };\n\n const payloadStr = JSON.stringify(payload);\n const contentLength = Buffer.from(payloadStr, 'utf8').length;\n diag.debug(`Instana Agent: ${host}, ${port}`);\n\n return new Promise((resolve, reject) => {\n const opts = {\n host,\n port,\n method: 'PUT',\n path: '/com.instana.plugin.nodejs.discovery',\n headers: {\n Accept: 'application/json',\n 'Content-Type': 'application/json; charset=UTF-8',\n 'Content-Length': contentLength,\n },\n timeout: agentTimeoutMs,\n };\n\n const req = http.request(opts, res => {\n res.setEncoding('utf8');\n let rawData = '';\n\n res.on('data', chunk => (rawData += chunk));\n res.on('end', () => {\n if (!res.statusCode || res.statusCode !== 200) {\n return reject(\n new Error(`Instana Agent returned status code ${res.statusCode}`)\n );\n }\n\n try {\n const data = JSON.parse(rawData);\n if (data.pid && data.agentUuid) {\n return resolve(data);\n }\n\n reject(\n new Error(`Invalid Instana Agent response format: ${data}.`)\n );\n } catch (e) {\n reject(e);\n }\n });\n });\n\n req.on('timeout', () =>\n reject(new Error('Instana Agent request timed out.'))\n );\n req.on('error', err => reject(err));\n\n req.write(Buffer.from(payloadStr), 'utf8');\n req.end();\n });\n }\n}\n\nexport const instanaAgentDetector = new InstanaAgentDetector();\n"]}
1
+ {"version":3,"file":"InstanaAgentDetector.js","sourceRoot":"","sources":["../../../src/detectors/InstanaAgentDetector.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,oBAAoB,CAAC;AACnD,OAAO,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAMtD,OAAO,EAAE,gBAAgB,EAAE,wBAAwB,EAAE,MAAM,YAAY,CAAC;AACxE,OAAO,KAAK,IAAI,MAAM,M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CAAC;YAEH,GAAG,CAAC,EAAE,CAAC,SAAS,EAAE,GAAG,EAAE,CACrB,MAAM,CAAC,IAAI,KAAK,CAAC,kCAAkC,CAAC,CAAC,CACtD,CAAC;YACF,GAAG,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,CAAC,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;YAEpC,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC,CAAC;YAC3C,GAAG,CAAC,GAAG,EAAE,CAAC;QACZ,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AAED,MAAM,CAAC,MAAM,oBAAoB,GAAG,IAAI,oBAAoB,EAAE,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { context, diag } from '@opentelemetry/api';\nimport { suppressTracing } from '@opentelemetry/core';\nimport {\n ResourceDetector,\n DetectedResource,\n DetectedResourceAttributes,\n} from '@opentelemetry/resources';\nimport { ATTR_PROCESS_PID, ATTR_SERVICE_INSTANCE_ID } from '../semconv';\nimport * as http from 'http';\n\nclass InstanaAgentDetector implements ResourceDetector {\n readonly INSTANA_AGENT_DEFAULT_HOST = 'localhost';\n readonly INSTANA_AGENT_DEFAULT_PORT = 42699;\n\n detect(): DetectedResource {\n const dataPromise = context.with(suppressTracing(context.active()), () =>\n this._gatherData()\n );\n\n const attrNames = [ATTR_PROCESS_PID, ATTR_SERVICE_INSTANCE_ID];\n\n const attributes = {} as DetectedResourceAttributes;\n attrNames.forEach(name => {\n // Each resource attribute is determined asynchronously in _gatherData().\n attributes[name] = dataPromise.then(data => data[name]);\n });\n\n return { attributes };\n }\n\n private async _gatherData(): Promise<DetectedResourceAttributes> {\n const host =\n process.env.INSTANA_AGENT_HOST || this.INSTANA_AGENT_DEFAULT_HOST;\n const port = Number(\n process.env.INSTANA_AGENT_PORT || this.INSTANA_AGENT_DEFAULT_PORT\n );\n\n try {\n const data = await this._retryHandler(host, port, 0);\n\n return {\n [ATTR_PROCESS_PID]: data.pid,\n [ATTR_SERVICE_INSTANCE_ID]: data.agentUuid,\n };\n } catch {\n return {};\n }\n }\n\n private timeout(ms: number) {\n return new Promise(resolve => setTimeout(resolve, ms).unref());\n }\n\n private async _retryHandler(\n host: string,\n port: number,\n tries: number\n ): Promise<{ pid: number; agentUuid: string }> {\n const MAX_TRIES = 3;\n\n try {\n return await this._fetchAgentData(host, port);\n } catch (err) {\n if (tries < MAX_TRIES) {\n diag.debug(\n `Retrying to connect to the Instana agent on ${host}:${port}....`\n );\n\n const retryTimeout = process.env.INSTANA_RETRY_TIMEOUT_MS\n ? Number(process.env.INSTANA_RETRY_TIMEOUT_MS)\n : 1000;\n\n await this.timeout(retryTimeout);\n return await this._retryHandler(host, port, tries + 1);\n }\n\n throw err;\n }\n }\n\n private async _fetchAgentData(\n host: string,\n port: number\n ): Promise<{ pid: number; agentUuid: string }> {\n const agentTimeoutMs = process.env.INSTANA_AGENT_TIMEOUT_MS\n ? Number(process.env.INSTANA_AGENT_TIMEOUT_MS)\n : 3 * 1000;\n\n const payload = {\n pid: process.pid,\n };\n\n const payloadStr = JSON.stringify(payload);\n const contentLength = Buffer.from(payloadStr, 'utf8').length;\n diag.debug(`Instana Agent: ${host}, ${port}`);\n\n return new Promise((resolve, reject) => {\n const opts = {\n host,\n port,\n method: 'PUT',\n path: '/com.instana.plugin.nodejs.discovery',\n headers: {\n Accept: 'application/json',\n 'Content-Type': 'application/json; charset=UTF-8',\n 'Content-Length': contentLength,\n },\n timeout: agentTimeoutMs,\n };\n\n const req = http.request(opts, res => {\n res.setEncoding('utf8');\n let rawData = '';\n\n res.on('data', chunk => (rawData += chunk));\n res.on('end', () => {\n if (!res.statusCode || res.statusCode !== 200) {\n return reject(\n new Error(`Instana Agent returned status code ${res.statusCode}`)\n );\n }\n\n try {\n const data = JSON.parse(rawData);\n if (data.pid && data.agentUuid) {\n return resolve(data);\n }\n\n reject(\n new Error(`Invalid Instana Agent response format: ${data}.`)\n );\n } catch (e) {\n reject(e);\n }\n });\n });\n\n req.on('timeout', () =>\n reject(new Error('Instana Agent request timed out.'))\n );\n req.on('error', err => reject(err));\n\n req.write(Buffer.from(payloadStr), 'utf8');\n req.end();\n });\n }\n}\n\nexport const instanaAgentDetector = new InstanaAgentDetector();\n"]}
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Process identifier (PID).
3
+ *
4
+ * @example 1234
5
+ *
6
+ * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
7
+ */
8
+ export declare const ATTR_PROCESS_PID: "process.pid";
9
+ /**
10
+ * The string ID of the service instance.
11
+ *
12
+ * @example 627cc493-f310-47de-96bd-71410b7dec09
13
+ *
14
+ * @note **MUST** be unique for each instance of the same `service.namespace,service.name` pair (in other words
15
+ * `service.namespace,service.name,service.instance.id` triplet **MUST** be globally unique). The ID helps to
16
+ * distinguish instances of the same service that exist at the same time (e.g. instances of a horizontally scaled
17
+ * service).
18
+ *
19
+ * Implementations, such as SDKs, are recommended to generate a random Version 1 or Version 4 [RFC
20
+ * 4122](https://www.ietf.org/rfc/rfc4122.txt) UUID, but are free to use an inherent unique ID as the source of
21
+ * this value if stability is desirable. In that case, the ID **SHOULD** be used as source of a UUID Version 5 and
22
+ * **SHOULD** use the following UUID as the namespace: `4d63009a-8d0f-11ee-aad7-4c796ed8e320`.
23
+ *
24
+ * UUIDs are typically recommended, as only an opaque value for the purposes of identifying a service instance is
25
+ * needed. Similar to what can be seen in the man page for the
26
+ * [`/etc/machine-id`](https://www.freedesktop.org/software/systemd/man/latest/machine-id.html) file, the underlying
27
+ * data, such as pod name and namespace should be treated as confidential, being the user's choice to expose it
28
+ * or not via another resource attribute.
29
+ *
30
+ * For applications running behind an application server (like unicorn), we do not recommend using one identifier
31
+ * for all processes participating in the application. Instead, it's recommended each division (e.g. a worker
32
+ * thread in unicorn) to have its own instance.id.
33
+ *
34
+ * It's not recommended for a Collector to set `service.instance.id` if it can't unambiguously determine the
35
+ * service instance that is generating that telemetry. For instance, creating an UUID based on `pod.name` will
36
+ * likely be wrong, as the Collector might not know from which container within that pod the telemetry originated.
37
+ * However, Collectors can set the `service.instance.id` if they can unambiguously determine the service instance
38
+ * for that telemetry. This is typically the case for scraping receivers, as they know the target address and
39
+ * port.
40
+ *
41
+ * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
42
+ */
43
+ export declare const ATTR_SERVICE_INSTANCE_ID: "service.instance.id";
44
+ //# sourceMappingURL=semconv.d.ts.map
@@ -0,0 +1,64 @@
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
+ * This file contains a copy of unstable semantic convention definitions
18
+ * used by this package.
19
+ * @see https://github.com/open-telemetry/opentelemetry-js/tree/main/semantic-conventions#unstable-semconv
20
+ */
21
+ /**
22
+ * Process identifier (PID).
23
+ *
24
+ * @example 1234
25
+ *
26
+ * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
27
+ */
28
+ export const ATTR_PROCESS_PID = 'process.pid';
29
+ /**
30
+ * The string ID of the service instance.
31
+ *
32
+ * @example 627cc493-f310-47de-96bd-71410b7dec09
33
+ *
34
+ * @note **MUST** be unique for each instance of the same `service.namespace,service.name` pair (in other words
35
+ * `service.namespace,service.name,service.instance.id` triplet **MUST** be globally unique). The ID helps to
36
+ * distinguish instances of the same service that exist at the same time (e.g. instances of a horizontally scaled
37
+ * service).
38
+ *
39
+ * Implementations, such as SDKs, are recommended to generate a random Version 1 or Version 4 [RFC
40
+ * 4122](https://www.ietf.org/rfc/rfc4122.txt) UUID, but are free to use an inherent unique ID as the source of
41
+ * this value if stability is desirable. In that case, the ID **SHOULD** be used as source of a UUID Version 5 and
42
+ * **SHOULD** use the following UUID as the namespace: `4d63009a-8d0f-11ee-aad7-4c796ed8e320`.
43
+ *
44
+ * UUIDs are typically recommended, as only an opaque value for the purposes of identifying a service instance is
45
+ * needed. Similar to what can be seen in the man page for the
46
+ * [`/etc/machine-id`](https://www.freedesktop.org/software/systemd/man/latest/machine-id.html) file, the underlying
47
+ * data, such as pod name and namespace should be treated as confidential, being the user's choice to expose it
48
+ * or not via another resource attribute.
49
+ *
50
+ * For applications running behind an application server (like unicorn), we do not recommend using one identifier
51
+ * for all processes participating in the application. Instead, it's recommended each division (e.g. a worker
52
+ * thread in unicorn) to have its own instance.id.
53
+ *
54
+ * It's not recommended for a Collector to set `service.instance.id` if it can't unambiguously determine the
55
+ * service instance that is generating that telemetry. For instance, creating an UUID based on `pod.name` will
56
+ * likely be wrong, as the Collector might not know from which container within that pod the telemetry originated.
57
+ * However, Collectors can set the `service.instance.id` if they can unambiguously determine the service instance
58
+ * for that telemetry. This is typically the case for scraping receivers, as they know the target address and
59
+ * port.
60
+ *
61
+ * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
62
+ */
63
+ export const ATTR_SERVICE_INSTANCE_ID = 'service.instance.id';
64
+ //# sourceMappingURL=semconv.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"semconv.js","sourceRoot":"","sources":["../../src/semconv.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH;;;;GAIG;AAEH;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,aAAsB,CAAC;AAEvD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG,qBAA8B,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/*\n * This file contains a copy of unstable semantic convention definitions\n * used by this package.\n * @see https://github.com/open-telemetry/opentelemetry-js/tree/main/semantic-conventions#unstable-semconv\n */\n\n/**\n * Process identifier (PID).\n *\n * @example 1234\n *\n * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.\n */\nexport const ATTR_PROCESS_PID = 'process.pid' as const;\n\n/**\n * The string ID of the service instance.\n *\n * @example 627cc493-f310-47de-96bd-71410b7dec09\n *\n * @note **MUST** be unique for each instance of the same `service.namespace,service.name` pair (in other words\n * `service.namespace,service.name,service.instance.id` triplet **MUST** be globally unique). The ID helps to\n * distinguish instances of the same service that exist at the same time (e.g. instances of a horizontally scaled\n * service).\n *\n * Implementations, such as SDKs, are recommended to generate a random Version 1 or Version 4 [RFC\n * 4122](https://www.ietf.org/rfc/rfc4122.txt) UUID, but are free to use an inherent unique ID as the source of\n * this value if stability is desirable. In that case, the ID **SHOULD** be used as source of a UUID Version 5 and\n * **SHOULD** use the following UUID as the namespace: `4d63009a-8d0f-11ee-aad7-4c796ed8e320`.\n *\n * UUIDs are typically recommended, as only an opaque value for the purposes of identifying a service instance is\n * needed. Similar to what can be seen in the man page for the\n * [`/etc/machine-id`](https://www.freedesktop.org/software/systemd/man/latest/machine-id.html) file, the underlying\n * data, such as pod name and namespace should be treated as confidential, being the user's choice to expose it\n * or not via another resource attribute.\n *\n * For applications running behind an application server (like unicorn), we do not recommend using one identifier\n * for all processes participating in the application. Instead, it's recommended each division (e.g. a worker\n * thread in unicorn) to have its own instance.id.\n *\n * It's not recommended for a Collector to set `service.instance.id` if it can't unambiguously determine the\n * service instance that is generating that telemetry. For instance, creating an UUID based on `pod.name` will\n * likely be wrong, as the Collector might not know from which container within that pod the telemetry originated.\n * However, Collectors can set the `service.instance.id` if they can unambiguously determine the service instance\n * for that telemetry. This is typically the case for scraping receivers, as they know the target address and\n * port.\n *\n * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.\n */\nexport const ATTR_SERVICE_INSTANCE_ID = 'service.instance.id' as const;\n"]}
@@ -18,17 +18,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
18
18
  exports.instanaAgentDetector = void 0;
19
19
  const api_1 = require("@opentelemetry/api");
20
20
  const core_1 = require("@opentelemetry/core");
21
- const semantic_conventions_1 = require("@opentelemetry/semantic-conventions");
21
+ const semconv_1 = require("../semconv");
22
22
  const http = require("http");
23
23
  class InstanaAgentDetector {
24
24
  INSTANA_AGENT_DEFAULT_HOST = 'localhost';
25
25
  INSTANA_AGENT_DEFAULT_PORT = 42699;
26
26
  detect() {
27
27
  const dataPromise = api_1.context.with((0, core_1.suppressTracing)(api_1.context.active()), () => this._gatherData());
28
- const attrNames = [
29
- semantic_conventions_1.SEMRESATTRS_PROCESS_PID,
30
- semantic_conventions_1.SEMRESATTRS_SERVICE_INSTANCE_ID,
31
- ];
28
+ const attrNames = [semconv_1.ATTR_PROCESS_PID, semconv_1.ATTR_SERVICE_INSTANCE_ID];
32
29
  const attributes = {};
33
30
  attrNames.forEach(name => {
34
31
  // Each resource attribute is determined asynchronously in _gatherData().
@@ -42,8 +39,8 @@ class InstanaAgentDetector {
42
39
  try {
43
40
  const data = await this._retryHandler(host, port, 0);
44
41
  return {
45
- [semantic_conventions_1.SEMRESATTRS_PROCESS_PID]: data.pid,
46
- [semantic_conventions_1.SEMRESATTRS_SERVICE_INSTANCE_ID]: data.agentUuid,
42
+ [semconv_1.ATTR_PROCESS_PID]: data.pid,
43
+ [semconv_1.ATTR_SERVICE_INSTANCE_ID]: data.agentUuid,
47
44
  };
48
45
  }
49
46
  catch {
@@ -1 +1 @@
1
- {"version":3,"file":"InstanaAgentDetector.js","sourceRoot":"","sources":["../../../src/detectors/InstanaAgentDetector.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,4CAAmD;AACnD,8CAAsD;AAMtD,8EAG6C;AAC7C,6BAA6B;AAE7B,MAAM,oBAAoB;IACf,0BAA0B,GAAG,WAAW,CAAC;IACzC,0BAA0B,GAAG,KAAK,CAAC;IAE5C,MAAM;QACJ,MAAM,WAAW,GAAG,aAAO,CAAC,IAAI,CAAC,IAAA,sBAAe,EAAC,aAAO,CAAC,MAAM,EAAE,CAAC,EAAE,GAAG,EAAE,CACvE,IAAI,CAAC,WAAW,EAAE,CACnB,CAAC;QAEF,MAAM,SAAS,GAAG;YAChB,8CAAuB;YACvB,sDAA+B;SAChC,CAAC;QAEF,MAAM,UAAU,GAAG,EAAgC,CAAC;QACpD,SAAS,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE;YACvB,yEAAyE;YACzE,UAAU,CAAC,IAAI,CAAC,GAAG,WAAW,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;QAC1D,CAAC,CAAC,CAAC;QAEH,OAAO,EAAE,UAAU,EAAE,CAAC;IACxB,CAAC;IAEO,KAAK,CAAC,WAAW;QACvB,MAAM,IAAI,GACR,OAAO,CAAC,GAAG,CAAC,kBAAk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AC,UAAU,IAAI,GAAG,CAAC,UAAU,KAAK,GAAG,EAAE;wBAC7C,OAAO,MAAM,CACX,IAAI,KAAK,CAAC,sCAAsC,GAAG,CAAC,UAAU,EAAE,CAAC,CAClE,CAAC;qBACH;oBAED,IAAI;wBACF,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC;wBACjC,IAAI,IAAI,CAAC,GAAG,IAAI,IAAI,CAAC,SAAS,EAAE;4BAC9B,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC;yBACtB;wBAED,MAAM,CACJ,IAAI,KAAK,CAAC,0CAA0C,IAAI,GAAG,CAAC,CAC7D,CAAC;qBACH;oBAAC,OAAO,CAAC,EAAE;wBACV,MAAM,CAAC,CAAC,CAAC,CAAC;qBACX;gBACH,CAAC,CAAC,CAAC;YACL,CAAC,CAAC,CAAC;YAEH,GAAG,CAAC,EAAE,CAAC,SAAS,EAAE,GAAG,EAAE,CACrB,MAAM,CAAC,IAAI,KAAK,CAAC,kCAAkC,CAAC,CAAC,CACtD,CAAC;YACF,GAAG,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,CAAC,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;YAEpC,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC,CAAC;YAC3C,GAAG,CAAC,GAAG,EAAE,CAAC;QACZ,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AAEY,QAAA,oBAAoB,GAAG,IAAI,oBAAoB,EAAE,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { context, diag } from '@opentelemetry/api';\nimport { suppressTracing } from '@opentelemetry/core';\nimport {\n ResourceDetector,\n DetectedResource,\n DetectedResourceAttributes,\n} from '@opentelemetry/resources';\nimport {\n SEMRESATTRS_PROCESS_PID,\n SEMRESATTRS_SERVICE_INSTANCE_ID,\n} from '@opentelemetry/semantic-conventions';\nimport * as http from 'http';\n\nclass InstanaAgentDetector implements ResourceDetector {\n readonly INSTANA_AGENT_DEFAULT_HOST = 'localhost';\n readonly INSTANA_AGENT_DEFAULT_PORT = 42699;\n\n detect(): DetectedResource {\n const dataPromise = context.with(suppressTracing(context.active()), () =>\n this._gatherData()\n );\n\n const attrNames = [\n SEMRESATTRS_PROCESS_PID,\n SEMRESATTRS_SERVICE_INSTANCE_ID,\n ];\n\n const attributes = {} as DetectedResourceAttributes;\n attrNames.forEach(name => {\n // Each resource attribute is determined asynchronously in _gatherData().\n attributes[name] = dataPromise.then(data => data[name]);\n });\n\n return { attributes };\n }\n\n private async _gatherData(): Promise<DetectedResourceAttributes> {\n const host =\n process.env.INSTANA_AGENT_HOST || this.INSTANA_AGENT_DEFAULT_HOST;\n const port = Number(\n process.env.INSTANA_AGENT_PORT || this.INSTANA_AGENT_DEFAULT_PORT\n );\n\n try {\n const data = await this._retryHandler(host, port, 0);\n\n return {\n [SEMRESATTRS_PROCESS_PID]: data.pid,\n [SEMRESATTRS_SERVICE_INSTANCE_ID]: data.agentUuid,\n };\n } catch {\n return {};\n }\n }\n\n private timeout(ms: number) {\n return new Promise(resolve => setTimeout(resolve, ms).unref());\n }\n\n private async _retryHandler(\n host: string,\n port: number,\n tries: number\n ): Promise<{ pid: number; agentUuid: string }> {\n const MAX_TRIES = 3;\n\n try {\n return await this._fetchAgentData(host, port);\n } catch (err) {\n if (tries < MAX_TRIES) {\n diag.debug(\n `Retrying to connect to the Instana agent on ${host}:${port}....`\n );\n\n const retryTimeout = process.env.INSTANA_RETRY_TIMEOUT_MS\n ? Number(process.env.INSTANA_RETRY_TIMEOUT_MS)\n : 1000;\n\n await this.timeout(retryTimeout);\n return await this._retryHandler(host, port, tries + 1);\n }\n\n throw err;\n }\n }\n\n private async _fetchAgentData(\n host: string,\n port: number\n ): Promise<{ pid: number; agentUuid: string }> {\n const agentTimeoutMs = process.env.INSTANA_AGENT_TIMEOUT_MS\n ? Number(process.env.INSTANA_AGENT_TIMEOUT_MS)\n : 3 * 1000;\n\n const payload = {\n pid: process.pid,\n };\n\n const payloadStr = JSON.stringify(payload);\n const contentLength = Buffer.from(payloadStr, 'utf8').length;\n diag.debug(`Instana Agent: ${host}, ${port}`);\n\n return new Promise((resolve, reject) => {\n const opts = {\n host,\n port,\n method: 'PUT',\n path: '/com.instana.plugin.nodejs.discovery',\n headers: {\n Accept: 'application/json',\n 'Content-Type': 'application/json; charset=UTF-8',\n 'Content-Length': contentLength,\n },\n timeout: agentTimeoutMs,\n };\n\n const req = http.request(opts, res => {\n res.setEncoding('utf8');\n let rawData = '';\n\n res.on('data', chunk => (rawData += chunk));\n res.on('end', () => {\n if (!res.statusCode || res.statusCode !== 200) {\n return reject(\n new Error(`Instana Agent returned status code ${res.statusCode}`)\n );\n }\n\n try {\n const data = JSON.parse(rawData);\n if (data.pid && data.agentUuid) {\n return resolve(data);\n }\n\n reject(\n new Error(`Invalid Instana Agent response format: ${data}.`)\n );\n } catch (e) {\n reject(e);\n }\n });\n });\n\n req.on('timeout', () =>\n reject(new Error('Instana Agent request timed out.'))\n );\n req.on('error', err => reject(err));\n\n req.write(Buffer.from(payloadStr), 'utf8');\n req.end();\n });\n }\n}\n\nexport const instanaAgentDetector = new InstanaAgentDetector();\n"]}
1
+ {"version":3,"file":"InstanaAgentDetector.js","sourceRoot":"","sources":["../../../src/detectors/InstanaAgentDetector.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,4CAAmD;AACnD,8CAAsD;AAMtD,wCAAwE;AACxE,6BAA6B;A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;YAEH,GAAG,CAAC,EAAE,CAAC,SAAS,EAAE,GAAG,EAAE,CACrB,MAAM,CAAC,IAAI,KAAK,CAAC,kCAAkC,CAAC,CAAC,CACtD,CAAC;YACF,GAAG,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,CAAC,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;YAEpC,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC,CAAC;YAC3C,GAAG,CAAC,GAAG,EAAE,CAAC;QACZ,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AAEY,QAAA,oBAAoB,GAAG,IAAI,oBAAoB,EAAE,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { context, diag } from '@opentelemetry/api';\nimport { suppressTracing } from '@opentelemetry/core';\nimport {\n ResourceDetector,\n DetectedResource,\n DetectedResourceAttributes,\n} from '@opentelemetry/resources';\nimport { ATTR_PROCESS_PID, ATTR_SERVICE_INSTANCE_ID } from '../semconv';\nimport * as http from 'http';\n\nclass InstanaAgentDetector implements ResourceDetector {\n readonly INSTANA_AGENT_DEFAULT_HOST = 'localhost';\n readonly INSTANA_AGENT_DEFAULT_PORT = 42699;\n\n detect(): DetectedResource {\n const dataPromise = context.with(suppressTracing(context.active()), () =>\n this._gatherData()\n );\n\n const attrNames = [ATTR_PROCESS_PID, ATTR_SERVICE_INSTANCE_ID];\n\n const attributes = {} as DetectedResourceAttributes;\n attrNames.forEach(name => {\n // Each resource attribute is determined asynchronously in _gatherData().\n attributes[name] = dataPromise.then(data => data[name]);\n });\n\n return { attributes };\n }\n\n private async _gatherData(): Promise<DetectedResourceAttributes> {\n const host =\n process.env.INSTANA_AGENT_HOST || this.INSTANA_AGENT_DEFAULT_HOST;\n const port = Number(\n process.env.INSTANA_AGENT_PORT || this.INSTANA_AGENT_DEFAULT_PORT\n );\n\n try {\n const data = await this._retryHandler(host, port, 0);\n\n return {\n [ATTR_PROCESS_PID]: data.pid,\n [ATTR_SERVICE_INSTANCE_ID]: data.agentUuid,\n };\n } catch {\n return {};\n }\n }\n\n private timeout(ms: number) {\n return new Promise(resolve => setTimeout(resolve, ms).unref());\n }\n\n private async _retryHandler(\n host: string,\n port: number,\n tries: number\n ): Promise<{ pid: number; agentUuid: string }> {\n const MAX_TRIES = 3;\n\n try {\n return await this._fetchAgentData(host, port);\n } catch (err) {\n if (tries < MAX_TRIES) {\n diag.debug(\n `Retrying to connect to the Instana agent on ${host}:${port}....`\n );\n\n const retryTimeout = process.env.INSTANA_RETRY_TIMEOUT_MS\n ? Number(process.env.INSTANA_RETRY_TIMEOUT_MS)\n : 1000;\n\n await this.timeout(retryTimeout);\n return await this._retryHandler(host, port, tries + 1);\n }\n\n throw err;\n }\n }\n\n private async _fetchAgentData(\n host: string,\n port: number\n ): Promise<{ pid: number; agentUuid: string }> {\n const agentTimeoutMs = process.env.INSTANA_AGENT_TIMEOUT_MS\n ? Number(process.env.INSTANA_AGENT_TIMEOUT_MS)\n : 3 * 1000;\n\n const payload = {\n pid: process.pid,\n };\n\n const payloadStr = JSON.stringify(payload);\n const contentLength = Buffer.from(payloadStr, 'utf8').length;\n diag.debug(`Instana Agent: ${host}, ${port}`);\n\n return new Promise((resolve, reject) => {\n const opts = {\n host,\n port,\n method: 'PUT',\n path: '/com.instana.plugin.nodejs.discovery',\n headers: {\n Accept: 'application/json',\n 'Content-Type': 'application/json; charset=UTF-8',\n 'Content-Length': contentLength,\n },\n timeout: agentTimeoutMs,\n };\n\n const req = http.request(opts, res => {\n res.setEncoding('utf8');\n let rawData = '';\n\n res.on('data', chunk => (rawData += chunk));\n res.on('end', () => {\n if (!res.statusCode || res.statusCode !== 200) {\n return reject(\n new Error(`Instana Agent returned status code ${res.statusCode}`)\n );\n }\n\n try {\n const data = JSON.parse(rawData);\n if (data.pid && data.agentUuid) {\n return resolve(data);\n }\n\n reject(\n new Error(`Invalid Instana Agent response format: ${data}.`)\n );\n } catch (e) {\n reject(e);\n }\n });\n });\n\n req.on('timeout', () =>\n reject(new Error('Instana Agent request timed out.'))\n );\n req.on('error', err => reject(err));\n\n req.write(Buffer.from(payloadStr), 'utf8');\n req.end();\n });\n }\n}\n\nexport const instanaAgentDetector = new InstanaAgentDetector();\n"]}
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Process identifier (PID).
3
+ *
4
+ * @example 1234
5
+ *
6
+ * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
7
+ */
8
+ export declare const ATTR_PROCESS_PID: "process.pid";
9
+ /**
10
+ * The string ID of the service instance.
11
+ *
12
+ * @example 627cc493-f310-47de-96bd-71410b7dec09
13
+ *
14
+ * @note **MUST** be unique for each instance of the same `service.namespace,service.name` pair (in other words
15
+ * `service.namespace,service.name,service.instance.id` triplet **MUST** be globally unique). The ID helps to
16
+ * distinguish instances of the same service that exist at the same time (e.g. instances of a horizontally scaled
17
+ * service).
18
+ *
19
+ * Implementations, such as SDKs, are recommended to generate a random Version 1 or Version 4 [RFC
20
+ * 4122](https://www.ietf.org/rfc/rfc4122.txt) UUID, but are free to use an inherent unique ID as the source of
21
+ * this value if stability is desirable. In that case, the ID **SHOULD** be used as source of a UUID Version 5 and
22
+ * **SHOULD** use the following UUID as the namespace: `4d63009a-8d0f-11ee-aad7-4c796ed8e320`.
23
+ *
24
+ * UUIDs are typically recommended, as only an opaque value for the purposes of identifying a service instance is
25
+ * needed. Similar to what can be seen in the man page for the
26
+ * [`/etc/machine-id`](https://www.freedesktop.org/software/systemd/man/latest/machine-id.html) file, the underlying
27
+ * data, such as pod name and namespace should be treated as confidential, being the user's choice to expose it
28
+ * or not via another resource attribute.
29
+ *
30
+ * For applications running behind an application server (like unicorn), we do not recommend using one identifier
31
+ * for all processes participating in the application. Instead, it's recommended each division (e.g. a worker
32
+ * thread in unicorn) to have its own instance.id.
33
+ *
34
+ * It's not recommended for a Collector to set `service.instance.id` if it can't unambiguously determine the
35
+ * service instance that is generating that telemetry. For instance, creating an UUID based on `pod.name` will
36
+ * likely be wrong, as the Collector might not know from which container within that pod the telemetry originated.
37
+ * However, Collectors can set the `service.instance.id` if they can unambiguously determine the service instance
38
+ * for that telemetry. This is typically the case for scraping receivers, as they know the target address and
39
+ * port.
40
+ *
41
+ * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
42
+ */
43
+ export declare const ATTR_SERVICE_INSTANCE_ID: "service.instance.id";
44
+ //# sourceMappingURL=semconv.d.ts.map
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ /*
3
+ * Copyright The OpenTelemetry Authors
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * https://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ Object.defineProperty(exports, "__esModule", { value: true });
18
+ exports.ATTR_SERVICE_INSTANCE_ID = exports.ATTR_PROCESS_PID = void 0;
19
+ /*
20
+ * This file contains a copy of unstable semantic convention definitions
21
+ * used by this package.
22
+ * @see https://github.com/open-telemetry/opentelemetry-js/tree/main/semantic-conventions#unstable-semconv
23
+ */
24
+ /**
25
+ * Process identifier (PID).
26
+ *
27
+ * @example 1234
28
+ *
29
+ * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
30
+ */
31
+ exports.ATTR_PROCESS_PID = 'process.pid';
32
+ /**
33
+ * The string ID of the service instance.
34
+ *
35
+ * @example 627cc493-f310-47de-96bd-71410b7dec09
36
+ *
37
+ * @note **MUST** be unique for each instance of the same `service.namespace,service.name` pair (in other words
38
+ * `service.namespace,service.name,service.instance.id` triplet **MUST** be globally unique). The ID helps to
39
+ * distinguish instances of the same service that exist at the same time (e.g. instances of a horizontally scaled
40
+ * service).
41
+ *
42
+ * Implementations, such as SDKs, are recommended to generate a random Version 1 or Version 4 [RFC
43
+ * 4122](https://www.ietf.org/rfc/rfc4122.txt) UUID, but are free to use an inherent unique ID as the source of
44
+ * this value if stability is desirable. In that case, the ID **SHOULD** be used as source of a UUID Version 5 and
45
+ * **SHOULD** use the following UUID as the namespace: `4d63009a-8d0f-11ee-aad7-4c796ed8e320`.
46
+ *
47
+ * UUIDs are typically recommended, as only an opaque value for the purposes of identifying a service instance is
48
+ * needed. Similar to what can be seen in the man page for the
49
+ * [`/etc/machine-id`](https://www.freedesktop.org/software/systemd/man/latest/machine-id.html) file, the underlying
50
+ * data, such as pod name and namespace should be treated as confidential, being the user's choice to expose it
51
+ * or not via another resource attribute.
52
+ *
53
+ * For applications running behind an application server (like unicorn), we do not recommend using one identifier
54
+ * for all processes participating in the application. Instead, it's recommended each division (e.g. a worker
55
+ * thread in unicorn) to have its own instance.id.
56
+ *
57
+ * It's not recommended for a Collector to set `service.instance.id` if it can't unambiguously determine the
58
+ * service instance that is generating that telemetry. For instance, creating an UUID based on `pod.name` will
59
+ * likely be wrong, as the Collector might not know from which container within that pod the telemetry originated.
60
+ * However, Collectors can set the `service.instance.id` if they can unambiguously determine the service instance
61
+ * for that telemetry. This is typically the case for scraping receivers, as they know the target address and
62
+ * port.
63
+ *
64
+ * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.
65
+ */
66
+ exports.ATTR_SERVICE_INSTANCE_ID = 'service.instance.id';
67
+ //# sourceMappingURL=semconv.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"semconv.js","sourceRoot":"","sources":["../../src/semconv.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH;;;;GAIG;AAEH;;;;;;GAMG;AACU,QAAA,gBAAgB,GAAG,aAAsB,CAAC;AAEvD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACU,QAAA,wBAAwB,GAAG,qBAA8B,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n/*\n * This file contains a copy of unstable semantic convention definitions\n * used by this package.\n * @see https://github.com/open-telemetry/opentelemetry-js/tree/main/semantic-conventions#unstable-semconv\n */\n\n/**\n * Process identifier (PID).\n *\n * @example 1234\n *\n * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.\n */\nexport const ATTR_PROCESS_PID = 'process.pid' as const;\n\n/**\n * The string ID of the service instance.\n *\n * @example 627cc493-f310-47de-96bd-71410b7dec09\n *\n * @note **MUST** be unique for each instance of the same `service.namespace,service.name` pair (in other words\n * `service.namespace,service.name,service.instance.id` triplet **MUST** be globally unique). The ID helps to\n * distinguish instances of the same service that exist at the same time (e.g. instances of a horizontally scaled\n * service).\n *\n * Implementations, such as SDKs, are recommended to generate a random Version 1 or Version 4 [RFC\n * 4122](https://www.ietf.org/rfc/rfc4122.txt) UUID, but are free to use an inherent unique ID as the source of\n * this value if stability is desirable. In that case, the ID **SHOULD** be used as source of a UUID Version 5 and\n * **SHOULD** use the following UUID as the namespace: `4d63009a-8d0f-11ee-aad7-4c796ed8e320`.\n *\n * UUIDs are typically recommended, as only an opaque value for the purposes of identifying a service instance is\n * needed. Similar to what can be seen in the man page for the\n * [`/etc/machine-id`](https://www.freedesktop.org/software/systemd/man/latest/machine-id.html) file, the underlying\n * data, such as pod name and namespace should be treated as confidential, being the user's choice to expose it\n * or not via another resource attribute.\n *\n * For applications running behind an application server (like unicorn), we do not recommend using one identifier\n * for all processes participating in the application. Instead, it's recommended each division (e.g. a worker\n * thread in unicorn) to have its own instance.id.\n *\n * It's not recommended for a Collector to set `service.instance.id` if it can't unambiguously determine the\n * service instance that is generating that telemetry. For instance, creating an UUID based on `pod.name` will\n * likely be wrong, as the Collector might not know from which container within that pod the telemetry originated.\n * However, Collectors can set the `service.instance.id` if they can unambiguously determine the service instance\n * for that telemetry. This is typically the case for scraping receivers, as they know the target address and\n * port.\n *\n * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`.\n */\nexport const ATTR_SERVICE_INSTANCE_ID = 'service.instance.id' as const;\n"]}
package/package.json CHANGED
@@ -1,17 +1,21 @@
1
1
  {
2
2
  "name": "@opentelemetry/resource-detector-instana",
3
- "version": "0.20.0",
3
+ "version": "0.22.0",
4
4
  "description": "OpenTelemetry SDK resource detector for Instana",
5
5
  "main": "build/src/index.js",
6
6
  "module": "build/esm/index.js",
7
7
  "types": "build/src/index.d.ts",
8
- "repository": "open-telemetry/opentelemetry-js-contrib",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "https://github.com/open-telemetry/opentelemetry-js-contrib.git",
11
+ "directory": "packages/resource-detector-instana"
12
+ },
9
13
  "scripts": {
10
14
  "clean": "tsc --build --clean tsconfig.json tsconfig.esm.json",
15
+ "setup:dev": "nx run-many -t compile -p @opentelemetry/resource-detector-instana",
11
16
  "compile": "tsc --build tsconfig.json tsconfig.esm.json",
12
17
  "lint": "eslint . --ext .ts",
13
18
  "lint:fix": "eslint . --ext .ts --fix",
14
- "prewatch": "npm run precompile",
15
19
  "prepublishOnly": "npm run compile",
16
20
  "test": "nyc mocha 'test/**/*.test.ts'",
17
21
  "tdd": "npm run test -- --watch-extensions ts --watch",
@@ -41,8 +45,8 @@
41
45
  },
42
46
  "devDependencies": {
43
47
  "@opentelemetry/api": "^1.3.0",
44
- "@opentelemetry/contrib-test-utils": "^0.47.0",
45
- "@opentelemetry/sdk-node": "^0.201.0",
48
+ "@opentelemetry/contrib-test-utils": "^0.49.0",
49
+ "@opentelemetry/sdk-node": "^0.203.0",
46
50
  "@types/mocha": "10.0.10",
47
51
  "@types/node": "18.18.14",
48
52
  "@types/semver": "7.5.8",
@@ -53,13 +57,12 @@
53
57
  },
54
58
  "dependencies": {
55
59
  "@opentelemetry/core": "^2.0.0",
56
- "@opentelemetry/resources": "^2.0.0",
57
- "@opentelemetry/semantic-conventions": "^1.27.0"
60
+ "@opentelemetry/resources": "^2.0.0"
58
61
  },
59
62
  "peerDependencies": {
60
63
  "@opentelemetry/api": "^1.3.0"
61
64
  },
62
- "homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/detectors/node/opentelemetry-resource-detector-instana#readme",
65
+ "homepage": "https://github.com/open-telemetry/opentelemetry-js-contrib/tree/main/packages/resource-detector-instana#readme",
63
66
  "sideEffects": false,
64
- "gitHead": "393b51596dc869983a03ce8857658029ca122a15"
67
+ "gitHead": "e7960a2061c0a039ffa57ed8dbb73d605d65f4f6"
65
68
  }