@opentelemetry/configuration 0.222.0 → 0.300.0-development.1

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.
Files changed (83) hide show
  1. package/dist/ConfigFactory.cjs +12 -0
  2. package/dist/ConfigFactory.cjs.map +1 -0
  3. package/dist/ConfigFactory.d.cts +6 -0
  4. package/dist/ConfigFactory.d.cts.map +1 -0
  5. package/dist/ConfigFactory.d.mts +6 -0
  6. package/dist/ConfigFactory.d.mts.map +1 -0
  7. package/dist/ConfigFactory.mjs +12 -0
  8. package/dist/ConfigFactory.mjs.map +1 -0
  9. package/dist/EnvDefinition.cjs +34 -0
  10. package/dist/EnvDefinition.cjs.map +1 -0
  11. package/dist/EnvDefinition.mjs +33 -0
  12. package/dist/EnvDefinition.mjs.map +1 -0
  13. package/dist/EnvReader.cjs +37 -0
  14. package/dist/EnvReader.cjs.map +1 -0
  15. package/dist/EnvReader.mjs +36 -0
  16. package/dist/EnvReader.mjs.map +1 -0
  17. package/dist/EnvironmentConfigFactory.cjs +354 -0
  18. package/dist/EnvironmentConfigFactory.cjs.map +1 -0
  19. package/dist/EnvironmentConfigFactory.mjs +347 -0
  20. package/dist/EnvironmentConfigFactory.mjs.map +1 -0
  21. package/dist/FileConfigFactory.cjs +141 -0
  22. package/dist/FileConfigFactory.cjs.map +1 -0
  23. package/{build/src/FileConfigFactory.d.ts → dist/FileConfigFactory.d.cts} +8 -12
  24. package/dist/FileConfigFactory.d.cts.map +1 -0
  25. package/dist/FileConfigFactory.d.mts +28 -0
  26. package/dist/FileConfigFactory.d.mts.map +1 -0
  27. package/dist/FileConfigFactory.mjs +134 -0
  28. package/dist/FileConfigFactory.mjs.map +1 -0
  29. package/dist/IConfigFactory.d.cts +13 -0
  30. package/dist/IConfigFactory.d.cts.map +1 -0
  31. package/dist/IConfigFactory.d.mts +13 -0
  32. package/dist/IConfigFactory.d.mts.map +1 -0
  33. package/dist/_virtual/_rolldown/runtime.cjs +25 -0
  34. package/dist/_virtual/_rolldown/runtime.mjs +4 -0
  35. package/dist/generated/types.d.cts +1662 -0
  36. package/dist/generated/types.d.cts.map +1 -0
  37. package/dist/generated/types.d.mts +1662 -0
  38. package/dist/generated/types.d.mts.map +1 -0
  39. package/dist/generated/validator.cjs +14385 -0
  40. package/dist/generated/validator.cjs.map +1 -0
  41. package/dist/generated/validator.mjs +14381 -0
  42. package/dist/generated/validator.mjs.map +1 -0
  43. package/dist/index.cjs +7 -0
  44. package/dist/index.d.cts +5 -0
  45. package/dist/index.d.mts +5 -0
  46. package/dist/index.mjs +3 -0
  47. package/dist/utils.cjs +137 -0
  48. package/dist/utils.cjs.map +1 -0
  49. package/dist/utils.mjs +129 -0
  50. package/dist/utils.mjs.map +1 -0
  51. package/package.json +28 -19
  52. package/build/src/ConfigFactory.d.ts +0 -3
  53. package/build/src/ConfigFactory.js +0 -19
  54. package/build/src/ConfigFactory.js.map +0 -1
  55. package/build/src/EnvDefinition.d.ts +0 -15
  56. package/build/src/EnvDefinition.js +0 -36
  57. package/build/src/EnvDefinition.js.map +0 -1
  58. package/build/src/EnvReader.d.ts +0 -24
  59. package/build/src/EnvReader.js +0 -60
  60. package/build/src/EnvReader.js.map +0 -1
  61. package/build/src/EnvironmentConfigFactory.d.ts +0 -19
  62. package/build/src/EnvironmentConfigFactory.js +0 -540
  63. package/build/src/EnvironmentConfigFactory.js.map +0 -1
  64. package/build/src/FileConfigFactory.js +0 -177
  65. package/build/src/FileConfigFactory.js.map +0 -1
  66. package/build/src/IConfigFactory.d.ts +0 -10
  67. package/build/src/IConfigFactory.js +0 -7
  68. package/build/src/IConfigFactory.js.map +0 -1
  69. package/build/src/generated/types.d.ts +0 -1659
  70. package/build/src/generated/types.js +0 -13
  71. package/build/src/generated/types.js.map +0 -1
  72. package/build/src/generated/validator.d.ts +0 -17
  73. package/build/src/generated/validator.js +0 -8533
  74. package/build/src/generated/validator.js.map +0 -1
  75. package/build/src/index.d.ts +0 -5
  76. package/build/src/index.js +0 -14
  77. package/build/src/index.js.map +0 -1
  78. package/build/src/utils.d.ts +0 -20
  79. package/build/src/utils.js +0 -188
  80. package/build/src/utils.js.map +0 -1
  81. package/build/src/version.d.ts +0 -2
  82. package/build/src/version.js +0 -10
  83. package/build/src/version.js.map +0 -1
package/dist/index.cjs ADDED
@@ -0,0 +1,7 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
+ const require_FileConfigFactory = require("./FileConfigFactory.cjs");
3
+ const require_ConfigFactory = require("./ConfigFactory.cjs");
4
+ exports.createConfigFactory = require_ConfigFactory.createConfigFactory;
5
+ exports.mergeHeadersConfig = require_FileConfigFactory.mergeHeadersConfig;
6
+ exports.mergePropagatorCompositeConfig = require_FileConfigFactory.mergePropagatorCompositeConfig;
7
+ exports.mergeResourceAttributesConfig = require_FileConfigFactory.mergeResourceAttributesConfig;
@@ -0,0 +1,5 @@
1
+ import { Aggregation, AttributeLimits, Base2ExponentialBucketHistogramAggregation, BatchLogRecordProcessor, BatchSpanProcessor, ConfigurationModel, ConsoleMetricExporter, ExperimentalPrometheusMetricExporter, ExplicitBucketHistogramAggregation, ExporterDefaultHistogramAggregation, ExporterTemporalityPreference, GrpcTls, HttpTls, IdGenerator, InstrumentType, LogRecordExporter, LogRecordLimits, LogRecordProcessor, LoggerProvider, MeterProvider, MetricProducer, MetricReader, NameStringValuePair, OtlpGrpcExporter, OtlpGrpcMetricExporter, OtlpHttpExporter, OtlpHttpMetricExporter, ParentBasedSampler, PeriodicMetricReader, Propagator, PullMetricExporter, PullMetricReader, PushMetricExporter, Resource, Sampler, SeverityNumber, SimpleLogRecordProcessor, SimpleSpanProcessor, SpanExporter, SpanLimits, SpanProcessor, TextMapPropagator, TraceIdRatioBasedSampler, TracerProvider, View } from "./generated/types.cjs";
2
+ import { ConfigFactory } from "./IConfigFactory.cjs";
3
+ import { createConfigFactory } from "./ConfigFactory.cjs";
4
+ import { mergeHeadersConfig, mergePropagatorCompositeConfig, mergeResourceAttributesConfig } from "./FileConfigFactory.cjs";
5
+ export { type Aggregation as AggregationConfigModel, type AttributeLimits as AttributeLimitsConfigModel, type Base2ExponentialBucketHistogramAggregation as Base2ExponentialBucketHistogramAggregationConfigModel, type BatchLogRecordProcessor as BatchLogRecordProcessorConfigModel, type BatchSpanProcessor as BatchSpanProcessorConfigModel, type ConfigFactory, type ConfigurationModel, type ConsoleMetricExporter as ConsoleMetricExporterConfigModel, type ExperimentalPrometheusMetricExporter as ExperimentalPrometheusMetricExporterConfigModel, type ExplicitBucketHistogramAggregation as ExplicitBucketHistogramAggregationConfigModel, type ExporterDefaultHistogramAggregation as ExporterDefaultHistogramAggregationConfigModel, type ExporterTemporalityPreference as ExporterTemporalityPreferenceConfigModel, type GrpcTls as GrpcTlsConfigModel, type HttpTls as HttpTlsConfigModel, type IdGenerator as IdGeneratorConfigModel, type InstrumentType as InstrumentTypeConfigModel, type LogRecordExporter as LogRecordExporterConfigModel, type LogRecordLimits as LogRecordLimitsConfigModel, type LogRecordProcessor as LogRecordProcessorConfigModel, type LoggerProvider as LoggerProviderConfigModel, type MeterProvider as MeterProviderConfigModel, type MetricProducer as MetricProducerConfigModel, type MetricReader as MetricReaderConfigModel, type NameStringValuePair as NameStringValuePairConfigModel, type OtlpGrpcExporter as OtlpGrpcExporterConfigModel, type OtlpGrpcMetricExporter as OtlpGrpcMetricExporterConfigModel, type OtlpHttpExporter as OtlpHttpExporterConfigModel, type OtlpHttpMetricExporter as OtlpHttpMetricExporterConfigModel, type ParentBasedSampler as ParentBasedSamplerConfigModel, type PeriodicMetricReader as PeriodicMetricReaderConfigModel, type Propagator as PropagatorConfigModel, type PullMetricExporter as PullMetricExporterConfigModel, type PullMetricReader as PullMetricReaderConfigModel, type PushMetricExporter as PushMetricExporterConfigModel, type Resource as ResourceConfigModel, type Sampler as SamplerConfigModel, type SeverityNumber as SeverityNumberConfigModel, type SimpleLogRecordProcessor as SimpleLogRecordProcessorConfigModel, type SimpleSpanProcessor as SimpleSpanProcessorConfigModel, type SpanExporter as SpanExporterConfigModel, type SpanLimits as SpanLimitsConfigModel, type SpanProcessor as SpanProcessorConfigModel, type TextMapPropagator as TextMapPropagatorConfigModel, type TraceIdRatioBasedSampler as TraceIdRatioBasedSamplerConfigModel, type TracerProvider as TracerProviderConfigModel, type View as ViewConfigModel, createConfigFactory, mergeHeadersConfig, mergePropagatorCompositeConfig, mergeResourceAttributesConfig };
@@ -0,0 +1,5 @@
1
+ import { Aggregation, AttributeLimits, Base2ExponentialBucketHistogramAggregation, BatchLogRecordProcessor, BatchSpanProcessor, ConfigurationModel, ConsoleMetricExporter, ExperimentalPrometheusMetricExporter, ExplicitBucketHistogramAggregation, ExporterDefaultHistogramAggregation, ExporterTemporalityPreference, GrpcTls, HttpTls, IdGenerator, InstrumentType, LogRecordExporter, LogRecordLimits, LogRecordProcessor, LoggerProvider, MeterProvider, MetricProducer, MetricReader, NameStringValuePair, OtlpGrpcExporter, OtlpGrpcMetricExporter, OtlpHttpExporter, OtlpHttpMetricExporter, ParentBasedSampler, PeriodicMetricReader, Propagator, PullMetricExporter, PullMetricReader, PushMetricExporter, Resource, Sampler, SeverityNumber, SimpleLogRecordProcessor, SimpleSpanProcessor, SpanExporter, SpanLimits, SpanProcessor, TextMapPropagator, TraceIdRatioBasedSampler, TracerProvider, View } from "./generated/types.mjs";
2
+ import { ConfigFactory } from "./IConfigFactory.mjs";
3
+ import { createConfigFactory } from "./ConfigFactory.mjs";
4
+ import { mergeHeadersConfig, mergePropagatorCompositeConfig, mergeResourceAttributesConfig } from "./FileConfigFactory.mjs";
5
+ export { type Aggregation as AggregationConfigModel, type AttributeLimits as AttributeLimitsConfigModel, type Base2ExponentialBucketHistogramAggregation as Base2ExponentialBucketHistogramAggregationConfigModel, type BatchLogRecordProcessor as BatchLogRecordProcessorConfigModel, type BatchSpanProcessor as BatchSpanProcessorConfigModel, type ConfigFactory, type ConfigurationModel, type ConsoleMetricExporter as ConsoleMetricExporterConfigModel, type ExperimentalPrometheusMetricExporter as ExperimentalPrometheusMetricExporterConfigModel, type ExplicitBucketHistogramAggregation as ExplicitBucketHistogramAggregationConfigModel, type ExporterDefaultHistogramAggregation as ExporterDefaultHistogramAggregationConfigModel, type ExporterTemporalityPreference as ExporterTemporalityPreferenceConfigModel, type GrpcTls as GrpcTlsConfigModel, type HttpTls as HttpTlsConfigModel, type IdGenerator as IdGeneratorConfigModel, type InstrumentType as InstrumentTypeConfigModel, type LogRecordExporter as LogRecordExporterConfigModel, type LogRecordLimits as LogRecordLimitsConfigModel, type LogRecordProcessor as LogRecordProcessorConfigModel, type LoggerProvider as LoggerProviderConfigModel, type MeterProvider as MeterProviderConfigModel, type MetricProducer as MetricProducerConfigModel, type MetricReader as MetricReaderConfigModel, type NameStringValuePair as NameStringValuePairConfigModel, type OtlpGrpcExporter as OtlpGrpcExporterConfigModel, type OtlpGrpcMetricExporter as OtlpGrpcMetricExporterConfigModel, type OtlpHttpExporter as OtlpHttpExporterConfigModel, type OtlpHttpMetricExporter as OtlpHttpMetricExporterConfigModel, type ParentBasedSampler as ParentBasedSamplerConfigModel, type PeriodicMetricReader as PeriodicMetricReaderConfigModel, type Propagator as PropagatorConfigModel, type PullMetricExporter as PullMetricExporterConfigModel, type PullMetricReader as PullMetricReaderConfigModel, type PushMetricExporter as PushMetricExporterConfigModel, type Resource as ResourceConfigModel, type Sampler as SamplerConfigModel, type SeverityNumber as SeverityNumberConfigModel, type SimpleLogRecordProcessor as SimpleLogRecordProcessorConfigModel, type SimpleSpanProcessor as SimpleSpanProcessorConfigModel, type SpanExporter as SpanExporterConfigModel, type SpanLimits as SpanLimitsConfigModel, type SpanProcessor as SpanProcessorConfigModel, type TextMapPropagator as TextMapPropagatorConfigModel, type TraceIdRatioBasedSampler as TraceIdRatioBasedSamplerConfigModel, type TracerProvider as TracerProviderConfigModel, type View as ViewConfigModel, createConfigFactory, mergeHeadersConfig, mergePropagatorCompositeConfig, mergeResourceAttributesConfig };
package/dist/index.mjs ADDED
@@ -0,0 +1,3 @@
1
+ import { mergeHeadersConfig, mergePropagatorCompositeConfig, mergeResourceAttributesConfig } from "./FileConfigFactory.mjs";
2
+ import { createConfigFactory } from "./ConfigFactory.mjs";
3
+ export { createConfigFactory, mergeHeadersConfig, mergePropagatorCompositeConfig, mergeResourceAttributesConfig };
package/dist/utils.cjs ADDED
@@ -0,0 +1,137 @@
1
+ const require_runtime = require("./_virtual/_rolldown/runtime.cjs");
2
+ let _opentelemetry_core = require("@opentelemetry/core");
3
+ let yaml = require("yaml");
4
+ yaml = require_runtime.__toESM(yaml);
5
+ //#region src/utils.ts
6
+ /**
7
+ * Handle (Environment) variable substitution per
8
+ * https://opentelemetry.io/docs/specs/otel/configuration/data-model/#environment-variable-substitution
9
+ *
10
+ * This changes the yaml.Document in-place.
11
+ * This must work with a yaml.Document, rather than a raw JS object from
12
+ * `yaml.parse()`, to distinguish between `foo: ${BAR}` and `foo: "${BAR}"`.
13
+ *
14
+ * Exported for testing.
15
+ */
16
+ function substituteEnvVars(doc) {
17
+ yaml.visit(doc, { Scalar: (key, node, _path) => {
18
+ if (key === "key") return;
19
+ if (typeof node.value !== "string") return;
20
+ let subbed = envVarSubst(node.value);
21
+ if (subbed !== node.value && node.type === yaml.Scalar.PLAIN) subbed = yamlScalarCoerce(subbed);
22
+ node.value = subbed;
23
+ } });
24
+ }
25
+ const ENV_SUBSTITUTION_RE = /^([a-zA-Z_][a-zA-Z0-9_]*)(?::-([^\n}]*))?$/;
26
+ /**
27
+ * Do environment variable substitution for the given string value.
28
+ */
29
+ function envVarSubst(s) {
30
+ const chunks = s.split(/(\$\$)/);
31
+ for (let i = 0; i < chunks.length; ++i) {
32
+ if (i % 2 === 1) {
33
+ chunks[i] = "$";
34
+ continue;
35
+ }
36
+ const SUBSTITUTION_REF_RE = /\$\{(?:env:)?([^}]+)\}/g;
37
+ let chunk = "";
38
+ let lastIndex = 0;
39
+ let match;
40
+ while ((match = SUBSTITUTION_REF_RE.exec(chunks[i])) !== null) {
41
+ chunk += chunks[i].slice(lastIndex, match.index);
42
+ const envMatch = ENV_SUBSTITUTION_RE.exec(match[1]);
43
+ if (!envMatch) throw new Error(`parse error: invalid env var substitution: ${match[0]}`);
44
+ const envName = envMatch[1];
45
+ const defaultValue = envMatch[2] ?? "";
46
+ chunk += (0, _opentelemetry_core.getStringFromEnv)(envName) || defaultValue;
47
+ lastIndex = SUBSTITUTION_REF_RE.lastIndex;
48
+ }
49
+ chunk += chunks[i].slice(lastIndex);
50
+ chunks[i] = chunk;
51
+ }
52
+ return chunks.join("");
53
+ }
54
+ /**
55
+ * Re-interpret a string value from env var substitution as a possible
56
+ * YAML number, boolean, or null value.
57
+ *
58
+ * If the interpretted value is any other type, we return the original
59
+ * string:
60
+ * - sequences and mappings may not result from env var substitution, per the spec
61
+ * - a re-parsed YAML string normalizes whitespace, which we do not want
62
+ */
63
+ function yamlScalarCoerce(value) {
64
+ let coerced;
65
+ try {
66
+ coerced = yaml.parse(value, { version: "1.2" });
67
+ } catch {
68
+ return value;
69
+ }
70
+ const type = typeof coerced;
71
+ if (coerced === null || type === "number" || type === "boolean") return coerced;
72
+ else return value;
73
+ }
74
+ function getGrpcTlsConfig(certificateFile, clientKeyFile, clientCertificateFile, insecure) {
75
+ if (certificateFile || clientKeyFile || clientCertificateFile) {
76
+ const tls = {};
77
+ if (certificateFile) tls.ca_file = certificateFile;
78
+ if (clientKeyFile) tls.key_file = clientKeyFile;
79
+ if (clientCertificateFile) tls.cert_file = clientCertificateFile;
80
+ if (insecure !== void 0) tls.insecure = insecure;
81
+ return tls;
82
+ }
83
+ }
84
+ function initializeDefaultConfiguration() {
85
+ return {
86
+ disabled: false,
87
+ log_level: "info",
88
+ resource: {},
89
+ attribute_limits: { attribute_count_limit: 128 }
90
+ };
91
+ }
92
+ function initializeDefaultTracerProviderConfiguration() {
93
+ return {
94
+ processors: [],
95
+ limits: {
96
+ attribute_count_limit: 128,
97
+ event_count_limit: 128,
98
+ link_count_limit: 128,
99
+ event_attribute_count_limit: 128,
100
+ link_attribute_count_limit: 128
101
+ },
102
+ sampler: { parent_based: { root: { always_on: null } } }
103
+ };
104
+ }
105
+ function initializeDefaultMeterProviderConfiguration() {
106
+ return {
107
+ readers: [],
108
+ views: [],
109
+ exemplar_filter: "trace_based"
110
+ };
111
+ }
112
+ function initializeDefaultLoggerProviderConfiguration() {
113
+ return {
114
+ processors: [],
115
+ limits: { attribute_count_limit: 128 },
116
+ "logger_configurator/development": {}
117
+ };
118
+ }
119
+ function getHttpTlsConfig(certificateFile, clientKeyFile, clientCertificateFile) {
120
+ if (certificateFile || clientKeyFile || clientCertificateFile) {
121
+ const tls = {};
122
+ if (certificateFile) tls.ca_file = certificateFile;
123
+ if (clientKeyFile) tls.key_file = clientKeyFile;
124
+ if (clientCertificateFile) tls.cert_file = clientCertificateFile;
125
+ return tls;
126
+ }
127
+ }
128
+ //#endregion
129
+ exports.getGrpcTlsConfig = getGrpcTlsConfig;
130
+ exports.getHttpTlsConfig = getHttpTlsConfig;
131
+ exports.initializeDefaultConfiguration = initializeDefaultConfiguration;
132
+ exports.initializeDefaultLoggerProviderConfiguration = initializeDefaultLoggerProviderConfiguration;
133
+ exports.initializeDefaultMeterProviderConfiguration = initializeDefaultMeterProviderConfiguration;
134
+ exports.initializeDefaultTracerProviderConfiguration = initializeDefaultTracerProviderConfiguration;
135
+ exports.substituteEnvVars = substituteEnvVars;
136
+
137
+ //# sourceMappingURL=utils.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.cjs","names":["getStringFromEnv"],"sources":["../src/utils.ts"],"sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport * as yaml from 'yaml';\nimport { getStringFromEnv } from '@opentelemetry/core';\nimport type { ConfigurationModel, GrpcTls, HttpTls } from './generated/types';\n\n/**\n * Handle (Environment) variable substitution per\n * https://opentelemetry.io/docs/specs/otel/configuration/data-model/#environment-variable-substitution\n *\n * This changes the yaml.Document in-place.\n * This must work with a yaml.Document, rather than a raw JS object from\n * `yaml.parse()`, to distinguish between `foo: ${BAR}` and `foo: \"${BAR}\"`.\n *\n * Exported for testing.\n */\nexport function substituteEnvVars(doc: yaml.Document) {\n // Visit each scalar string value in the document. These are\n // the candidates for env var substitution.\n yaml.visit(doc, {\n Scalar: (key, node, _path) => {\n if (key === 'key') return; // skip mapping keys\n if (typeof node.value !== 'string') return;\n let subbed: string | null | number | boolean = envVarSubst(node.value);\n if (subbed !== node.value && node.type === yaml.Scalar.PLAIN) {\n // \"PLAIN\" here is a simple YAML value (e.g. 42 in `foo: 42`).\n // I.e., not quoted (`foo: \"42\"`) or in a block.\n subbed = yamlScalarCoerce(subbed);\n }\n node.value = subbed;\n },\n });\n}\n\n// ENV_SUBSTITUTION_RE *mostly* matches the `ENV-SUBSTITUTION` ABNF from the\n// spec with the exception of the DEFAULT-VALUE: we are using `[^\\n}]*`\n// (copying the OTel Java regex) rather than a regex closer to ABNF\n// `*(VCHAR-WSP-NO-RBRACE)` (which is slightly ambiguous on what whitespace is\n// allowed in WSP).\nconst ENV_SUBSTITUTION_RE = /^([a-zA-Z_][a-zA-Z0-9_]*)(?::-([^\\n}]*))?$/;\n\n/**\n * Do environment variable substitution for the given string value.\n */\nfunction envVarSubst(s: string): string {\n const ESCAPE_RE = /(\\$\\$)/;\n const chunks = s.split(ESCAPE_RE);\n for (let i = 0; i < chunks.length; ++i) {\n if (i % 2 === 1) {\n // Odd chunks are matched escape sequences, i.e. '$$'.\n chunks[i] = '$';\n continue;\n }\n\n // Even chunks are processed for possible substition matches.\n const SUBSTITUTION_REF_RE = /\\$\\{(?:env:)?([^}]+)\\}/g;\n let chunk = '';\n let lastIndex = 0;\n let match: RegExpExecArray | null;\n while ((match = SUBSTITUTION_REF_RE.exec(chunks[i])) !== null) {\n chunk += chunks[i].slice(lastIndex, match.index);\n const envMatch = ENV_SUBSTITUTION_RE.exec(match[1]);\n if (!envMatch) {\n // E.g.: `key: ${STRING_VALUE:?error}` test case\n throw new Error(\n `parse error: invalid env var substitution: ${match[0]}`\n );\n }\n const envName = envMatch[1];\n const defaultValue = envMatch[2] ?? '';\n chunk += getStringFromEnv(envName) || defaultValue;\n lastIndex = SUBSTITUTION_REF_RE.lastIndex;\n }\n chunk += chunks[i].slice(lastIndex);\n chunks[i] = chunk;\n }\n\n const result = chunks.join('');\n return result;\n}\n\n/**\n * Re-interpret a string value from env var substitution as a possible\n * YAML number, boolean, or null value.\n *\n * If the interpretted value is any other type, we return the original\n * string:\n * - sequences and mappings may not result from env var substitution, per the spec\n * - a re-parsed YAML string normalizes whitespace, which we do not want\n */\nfunction yamlScalarCoerce(value: string): string | null | number | boolean {\n let coerced;\n try {\n coerced = yaml.parse(value, { version: '1.2' });\n } catch {\n return value;\n }\n const type = typeof coerced;\n if (coerced === null || type === 'number' || type === 'boolean') {\n return coerced;\n } else {\n return value;\n }\n}\n\nexport function getGrpcTlsConfig(\n certificateFile?: string,\n clientKeyFile?: string,\n clientCertificateFile?: string,\n insecure?: boolean\n): GrpcTls | undefined {\n if (certificateFile || clientKeyFile || clientCertificateFile) {\n const tls: GrpcTls = {};\n if (certificateFile) {\n tls.ca_file = certificateFile;\n }\n if (clientKeyFile) {\n tls.key_file = clientKeyFile;\n }\n if (clientCertificateFile) {\n tls.cert_file = clientCertificateFile;\n }\n if (insecure !== undefined) {\n tls.insecure = insecure;\n }\n return tls;\n }\n return undefined;\n}\n\nexport function initializeDefaultConfiguration(): ConfigurationModel {\n return {\n disabled: false,\n log_level: 'info',\n resource: {},\n attribute_limits: {\n attribute_count_limit: 128,\n },\n };\n}\n\nexport function initializeDefaultTracerProviderConfiguration(): NonNullable<\n ConfigurationModel['tracer_provider']\n> {\n return {\n processors: [],\n limits: {\n attribute_count_limit: 128,\n event_count_limit: 128,\n link_count_limit: 128,\n event_attribute_count_limit: 128,\n link_attribute_count_limit: 128,\n },\n sampler: {\n parent_based: {\n root: { always_on: null },\n },\n },\n };\n}\n\nexport function initializeDefaultMeterProviderConfiguration(): NonNullable<\n ConfigurationModel['meter_provider']\n> {\n return {\n readers: [],\n views: [],\n exemplar_filter: 'trace_based',\n };\n}\n\nexport function initializeDefaultLoggerProviderConfiguration(): NonNullable<\n ConfigurationModel['logger_provider']\n> {\n return {\n processors: [],\n limits: { attribute_count_limit: 128 },\n 'logger_configurator/development': {},\n };\n}\n\nexport function getHttpTlsConfig(\n certificateFile?: string,\n clientKeyFile?: string,\n clientCertificateFile?: string\n): HttpTls | undefined {\n if (certificateFile || clientKeyFile || clientCertificateFile) {\n const tls: HttpTls = {};\n if (certificateFile) {\n tls.ca_file = certificateFile;\n }\n if (clientKeyFile) {\n tls.key_file = clientKeyFile;\n }\n if (clientCertificateFile) {\n tls.cert_file = clientCertificateFile;\n }\n return tls;\n }\n return undefined;\n}\n"],"mappings":";;;;;;;;;;;;;;;AAmBA,SAAgB,kBAAkB,KAAoB;CAGpD,KAAK,MAAM,KAAK,EACd,SAAS,KAAK,MAAM,UAAU;EAC5B,IAAI,QAAQ,OAAO;EACnB,IAAI,OAAO,KAAK,UAAU,UAAU;EACpC,IAAI,SAA2C,YAAY,KAAK,KAAK;EACrE,IAAI,WAAW,KAAK,SAAS,KAAK,SAAS,KAAK,OAAO,OAGrD,SAAS,iBAAiB,MAAM;EAElC,KAAK,QAAQ;CACf,EACF,CAAC;AACH;AAOA,MAAM,sBAAsB;;;;AAK5B,SAAS,YAAY,GAAmB;CAEtC,MAAM,SAAS,EAAE,MAAM,QAAS;CAChC,KAAK,IAAI,IAAI,GAAG,IAAI,OAAO,QAAQ,EAAE,GAAG;EACtC,IAAI,IAAI,MAAM,GAAG;GAEf,OAAO,KAAK;GACZ;EACF;EAGA,MAAM,sBAAsB;EAC5B,IAAI,QAAQ;EACZ,IAAI,YAAY;EAChB,IAAI;EACJ,QAAQ,QAAQ,oBAAoB,KAAK,OAAO,EAAE,OAAO,MAAM;GAC7D,SAAS,OAAO,EAAE,CAAC,MAAM,WAAW,MAAM,KAAK;GAC/C,MAAM,WA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ACnB;AACF;AAEA,SAAgB,+CAEd;CACA,OAAO;EACL,YAAY,CAAC;EACb,QAAQ,EAAE,uBAAuB,IAAI;EACrC,mCAAmC,CAAC;CACtC;AACF;AAEA,SAAgB,iBACd,iBACA,eACA,uBACqB;CACrB,IAAI,mBAAmB,iBAAiB,uBAAuB;EAC7D,MAAM,MAAe,CAAC;EACtB,IAAI,iBACF,IAAI,UAAU;EAEhB,IAAI,eACF,IAAI,WAAW;EAEjB,IAAI,uBACF,IAAI,YAAY;EAElB,OAAO;CACT;AAEF"}
package/dist/utils.mjs ADDED
@@ -0,0 +1,129 @@
1
+ import { getStringFromEnv } from "@opentelemetry/core";
2
+ import * as yaml from "yaml";
3
+ //#region src/utils.ts
4
+ /**
5
+ * Handle (Environment) variable substitution per
6
+ * https://opentelemetry.io/docs/specs/otel/configuration/data-model/#environment-variable-substitution
7
+ *
8
+ * This changes the yaml.Document in-place.
9
+ * This must work with a yaml.Document, rather than a raw JS object from
10
+ * `yaml.parse()`, to distinguish between `foo: ${BAR}` and `foo: "${BAR}"`.
11
+ *
12
+ * Exported for testing.
13
+ */
14
+ function substituteEnvVars(doc) {
15
+ yaml.visit(doc, { Scalar: (key, node, _path) => {
16
+ if (key === "key") return;
17
+ if (typeof node.value !== "string") return;
18
+ let subbed = envVarSubst(node.value);
19
+ if (subbed !== node.value && node.type === yaml.Scalar.PLAIN) subbed = yamlScalarCoerce(subbed);
20
+ node.value = subbed;
21
+ } });
22
+ }
23
+ const ENV_SUBSTITUTION_RE = /^([a-zA-Z_][a-zA-Z0-9_]*)(?::-([^\n}]*))?$/;
24
+ /**
25
+ * Do environment variable substitution for the given string value.
26
+ */
27
+ function envVarSubst(s) {
28
+ const chunks = s.split(/(\$\$)/);
29
+ for (let i = 0; i < chunks.length; ++i) {
30
+ if (i % 2 === 1) {
31
+ chunks[i] = "$";
32
+ continue;
33
+ }
34
+ const SUBSTITUTION_REF_RE = /\$\{(?:env:)?([^}]+)\}/g;
35
+ let chunk = "";
36
+ let lastIndex = 0;
37
+ let match;
38
+ while ((match = SUBSTITUTION_REF_RE.exec(chunks[i])) !== null) {
39
+ chunk += chunks[i].slice(lastIndex, match.index);
40
+ const envMatch = ENV_SUBSTITUTION_RE.exec(match[1]);
41
+ if (!envMatch) throw new Error(`parse error: invalid env var substitution: ${match[0]}`);
42
+ const envName = envMatch[1];
43
+ const defaultValue = envMatch[2] ?? "";
44
+ chunk += getStringFromEnv(envName) || defaultValue;
45
+ lastIndex = SUBSTITUTION_REF_RE.lastIndex;
46
+ }
47
+ chunk += chunks[i].slice(lastIndex);
48
+ chunks[i] = chunk;
49
+ }
50
+ return chunks.join("");
51
+ }
52
+ /**
53
+ * Re-interpret a string value from env var substitution as a possible
54
+ * YAML number, boolean, or null value.
55
+ *
56
+ * If the interpretted value is any other type, we return the original
57
+ * string:
58
+ * - sequences and mappings may not result from env var substitution, per the spec
59
+ * - a re-parsed YAML string normalizes whitespace, which we do not want
60
+ */
61
+ function yamlScalarCoerce(value) {
62
+ let coerced;
63
+ try {
64
+ coerced = yaml.parse(value, { version: "1.2" });
65
+ } catch {
66
+ return value;
67
+ }
68
+ const type = typeof coerced;
69
+ if (coerced === null || type === "number" || type === "boolean") return coerced;
70
+ else return value;
71
+ }
72
+ function getGrpcTlsConfig(certificateFile, clientKeyFile, clientCertificateFile, insecure) {
73
+ if (certificateFile || clientKeyFile || clientCertificateFile) {
74
+ const tls = {};
75
+ if (certificateFile) tls.ca_file = certificateFile;
76
+ if (clientKeyFile) tls.key_file = clientKeyFile;
77
+ if (clientCertificateFile) tls.cert_file = clientCertificateFile;
78
+ if (insecure !== void 0) tls.insecure = insecure;
79
+ return tls;
80
+ }
81
+ }
82
+ function initializeDefaultConfiguration() {
83
+ return {
84
+ disabled: false,
85
+ log_level: "info",
86
+ resource: {},
87
+ attribute_limits: { attribute_count_limit: 128 }
88
+ };
89
+ }
90
+ function initializeDefaultTracerProviderConfiguration() {
91
+ return {
92
+ processors: [],
93
+ limits: {
94
+ attribute_count_limit: 128,
95
+ event_count_limit: 128,
96
+ link_count_limit: 128,
97
+ event_attribute_count_limit: 128,
98
+ link_attribute_count_limit: 128
99
+ },
100
+ sampler: { parent_based: { root: { always_on: null } } }
101
+ };
102
+ }
103
+ function initializeDefaultMeterProviderConfiguration() {
104
+ return {
105
+ readers: [],
106
+ views: [],
107
+ exemplar_filter: "trace_based"
108
+ };
109
+ }
110
+ function initializeDefaultLoggerProviderConfiguration() {
111
+ return {
112
+ processors: [],
113
+ limits: { attribute_count_limit: 128 },
114
+ "logger_configurator/development": {}
115
+ };
116
+ }
117
+ function getHttpTlsConfig(certificateFile, clientKeyFile, clientCertificateFile) {
118
+ if (certificateFile || clientKeyFile || clientCertificateFile) {
119
+ const tls = {};
120
+ if (certificateFile) tls.ca_file = certificateFile;
121
+ if (clientKeyFile) tls.key_file = clientKeyFile;
122
+ if (clientCertificateFile) tls.cert_file = clientCertificateFile;
123
+ return tls;
124
+ }
125
+ }
126
+ //#endregion
127
+ export { getGrpcTlsConfig, getHttpTlsConfig, initializeDefaultConfiguration, initializeDefaultLoggerProviderConfiguration, initializeDefaultMeterProviderConfiguration, initializeDefaultTracerProviderConfiguration, substituteEnvVars };
128
+
129
+ //# sourceMappingURL=utils.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.mjs","names":[],"sources":["../src/utils.ts"],"sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport * as yaml from 'yaml';\nimport { getStringFromEnv } from '@opentelemetry/core';\nimport type { ConfigurationModel, GrpcTls, HttpTls } from './generated/types';\n\n/**\n * Handle (Environment) variable substitution per\n * https://opentelemetry.io/docs/specs/otel/configuration/data-model/#environment-variable-substitution\n *\n * This changes the yaml.Document in-place.\n * This must work with a yaml.Document, rather than a raw JS object from\n * `yaml.parse()`, to distinguish between `foo: ${BAR}` and `foo: \"${BAR}\"`.\n *\n * Exported for testing.\n */\nexport function substituteEnvVars(doc: yaml.Document) {\n // Visit each scalar string value in the document. These are\n // the candidates for env var substitution.\n yaml.visit(doc, {\n Scalar: (key, node, _path) => {\n if (key === 'key') return; // skip mapping keys\n if (typeof node.value !== 'string') return;\n let subbed: string | null | number | boolean = envVarSubst(node.value);\n if (subbed !== node.value && node.type === yaml.Scalar.PLAIN) {\n // \"PLAIN\" here is a simple YAML value (e.g. 42 in `foo: 42`).\n // I.e., not quoted (`foo: \"42\"`) or in a block.\n subbed = yamlScalarCoerce(subbed);\n }\n node.value = subbed;\n },\n });\n}\n\n// ENV_SUBSTITUTION_RE *mostly* matches the `ENV-SUBSTITUTION` ABNF from the\n// spec with the exception of the DEFAULT-VALUE: we are using `[^\\n}]*`\n// (copying the OTel Java regex) rather than a regex closer to ABNF\n// `*(VCHAR-WSP-NO-RBRACE)` (which is slightly ambiguous on what whitespace is\n// allowed in WSP).\nconst ENV_SUBSTITUTION_RE = /^([a-zA-Z_][a-zA-Z0-9_]*)(?::-([^\\n}]*))?$/;\n\n/**\n * Do environment variable substitution for the given string value.\n */\nfunction envVarSubst(s: string): string {\n const ESCAPE_RE = /(\\$\\$)/;\n const chunks = s.split(ESCAPE_RE);\n for (let i = 0; i < chunks.length; ++i) {\n if (i % 2 === 1) {\n // Odd chunks are matched escape sequences, i.e. '$$'.\n chunks[i] = '$';\n continue;\n }\n\n // Even chunks are processed for possible substition matches.\n const SUBSTITUTION_REF_RE = /\\$\\{(?:env:)?([^}]+)\\}/g;\n let chunk = '';\n let lastIndex = 0;\n let match: RegExpExecArray | null;\n while ((match = SUBSTITUTION_REF_RE.exec(chunks[i])) !== null) {\n chunk += chunks[i].slice(lastIndex, match.index);\n const envMatch = ENV_SUBSTITUTION_RE.exec(match[1]);\n if (!envMatch) {\n // E.g.: `key: ${STRING_VALUE:?error}` test case\n throw new Error(\n `parse error: invalid env var substitution: ${match[0]}`\n );\n }\n const envName = envMatch[1];\n const defaultValue = envMatch[2] ?? '';\n chunk += getStringFromEnv(envName) || defaultValue;\n lastIndex = SUBSTITUTION_REF_RE.lastIndex;\n }\n chunk += chunks[i].slice(lastIndex);\n chunks[i] = chunk;\n }\n\n const result = chunks.join('');\n return result;\n}\n\n/**\n * Re-interpret a string value from env var substitution as a possible\n * YAML number, boolean, or null value.\n *\n * If the interpretted value is any other type, we return the original\n * string:\n * - sequences and mappings may not result from env var substitution, per the spec\n * - a re-parsed YAML string normalizes whitespace, which we do not want\n */\nfunction yamlScalarCoerce(value: string): string | null | number | boolean {\n let coerced;\n try {\n coerced = yaml.parse(value, { version: '1.2' });\n } catch {\n return value;\n }\n const type = typeof coerced;\n if (coerced === null || type === 'number' || type === 'boolean') {\n return coerced;\n } else {\n return value;\n }\n}\n\nexport function getGrpcTlsConfig(\n certificateFile?: string,\n clientKeyFile?: string,\n clientCertificateFile?: string,\n insecure?: boolean\n): GrpcTls | undefined {\n if (certificateFile || clientKeyFile || clientCertificateFile) {\n const tls: GrpcTls = {};\n if (certificateFile) {\n tls.ca_file = certificateFile;\n }\n if (clientKeyFile) {\n tls.key_file = clientKeyFile;\n }\n if (clientCertificateFile) {\n tls.cert_file = clientCertificateFile;\n }\n if (insecure !== undefined) {\n tls.insecure = insecure;\n }\n return tls;\n }\n return undefined;\n}\n\nexport function initializeDefaultConfiguration(): ConfigurationModel {\n return {\n disabled: false,\n log_level: 'info',\n resource: {},\n attribute_limits: {\n attribute_count_limit: 128,\n },\n };\n}\n\nexport function initializeDefaultTracerProviderConfiguration(): NonNullable<\n ConfigurationModel['tracer_provider']\n> {\n return {\n processors: [],\n limits: {\n attribute_count_limit: 128,\n event_count_limit: 128,\n link_count_limit: 128,\n event_attribute_count_limit: 128,\n link_attribute_count_limit: 128,\n },\n sampler: {\n parent_based: {\n root: { always_on: null },\n },\n },\n };\n}\n\nexport function initializeDefaultMeterProviderConfiguration(): NonNullable<\n ConfigurationModel['meter_provider']\n> {\n return {\n readers: [],\n views: [],\n exemplar_filter: 'trace_based',\n };\n}\n\nexport function initializeDefaultLoggerProviderConfiguration(): NonNullable<\n ConfigurationModel['logger_provider']\n> {\n return {\n processors: [],\n limits: { attribute_count_limit: 128 },\n 'logger_configurator/development': {},\n };\n}\n\nexport function getHttpTlsConfig(\n certificateFile?: string,\n clientKeyFile?: string,\n clientCertificateFile?: string\n): HttpTls | undefined {\n if (certificateFile || clientKeyFile || clientCertificateFile) {\n const tls: HttpTls = {};\n if (certificateFile) {\n tls.ca_file = certificateFile;\n }\n if (clientKeyFile) {\n tls.key_file = clientKeyFile;\n }\n if (clientCertificateFile) {\n tls.cert_file = clientCertificateFile;\n }\n return tls;\n }\n return undefined;\n}\n"],"mappings":";;;;;;;;;;;;;AAmBA,SAAgB,kBAAkB,KAAoB;CAGpD,KAAK,MAAM,KAAK,EACd,SAAS,KAAK,MAAM,UAAU;EAC5B,IAAI,QAAQ,OAAO;EACnB,IAAI,OAAO,KAAK,UAAU,UAAU;EACpC,IAAI,SAA2C,YAAY,KAAK,KAAK;EACrE,IAAI,WAAW,KAAK,SAAS,KAAK,SAAS,KAAK,OAAO,OAGrD,SAAS,iBAAiB,MAAM;EAElC,KAAK,QAAQ;CACf,EACF,CAAC;AACH;AAOA,MAAM,sBAAsB;;;;AAK5B,SAAS,YAAY,GAAmB;CAEtC,MAAM,SAAS,EAAE,MAAM,QAAS;CAChC,KAAK,IAAI,IAAI,GAAG,IAAI,OAAO,QAAQ,EAAE,GAAG;EACtC,IAAI,IAAI,MAAM,GAAG;GAEf,OAAO,KAAK;GACZ;EACF;EAGA,MAAM,sBAAsB;EAC5B,IAAI,QAAQ;EACZ,IAAI,YAAY;EAChB,IAAI;EACJ,QAAQ,QAAQ,oBAAoB,KAAK,OAAO,EAAE,OAAO,MAAM;GAC7D,SAAS,OAAO,EAAE,CAAC,MAAM,WAAW,MAAM,KAAK;GAC/C,MAAM,WAAW,oBAAoB,KAAK,MAAM,EAAE;GAClD,IAAI,CAAC,UAEH,MAAM,IAAI,MACR,8CAA8C,MAAM,IACtD;GAEF,MAAM,UAAU,SAAS;GACzB,MAAM,eAA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BACqB;CACrB,IAAI,mBAAmB,iBAAiB,uBAAuB;EAC7D,MAAM,MAAe,CAAC;EACtB,IAAI,iBACF,IAAI,UAAU;EAEhB,IAAI,eACF,IAAI,WAAW;EAEjB,IAAI,uBACF,IAAI,YAAY;EAElB,OAAO;CACT;AAEF"}
package/package.json CHANGED
@@ -1,23 +1,34 @@
1
1
  {
2
2
  "name": "@opentelemetry/configuration",
3
- "version": "0.222.0",
3
+ "version": "0.300.0-development.1",
4
4
  "description": "OpenTelemetry Configuration",
5
- "main": "build/src/index.js",
6
- "types": "build/src/index.d.ts",
5
+ "main": "./dist/index.cjs",
6
+ "types": "./dist/index.d.cts",
7
+ "exports": {
8
+ ".": {
9
+ "require": {
10
+ "types": "./dist/index.d.cts",
11
+ "default": "./dist/index.cjs"
12
+ },
13
+ "default": {
14
+ "types": "./dist/index.d.mts",
15
+ "default": "./dist/index.mjs"
16
+ }
17
+ }
18
+ },
7
19
  "repository": "open-telemetry/opentelemetry-js",
8
20
  "scripts": {
9
21
  "prepublishOnly": "npm run compile",
10
- "compile": "tsc --build",
11
- "clean": "tsc --build --clean",
22
+ "compile": "tsdown",
23
+ "clean": "rimraf dist build",
12
24
  "generate:config": "node ./scripts/generate-config.js",
13
25
  "test": "nyc mocha test/**/*.test.ts",
14
26
  "lint": "eslint .",
15
27
  "lint:fix": "eslint . --fix",
16
28
  "version": "node ../../../scripts/version-update.js",
17
- "watch": "tsc --build --watch",
18
- "prewatch": "npm run precompile",
19
- "peer-api-check": "node ../../../scripts/peer-api-check.js",
20
- "align-api-deps": "node ../../../scripts/align-api-deps.js"
29
+ "watch": "tsdown --watch --no-clean",
30
+ "peer-api-check": "node ../../../scripts/peer-api-check.mjs",
31
+ "align-api-deps": "node ../../../scripts/align-api-deps.mjs"
21
32
  },
22
33
  "keywords": [
23
34
  "opentelemetry",
@@ -26,39 +37,37 @@
26
37
  "author": "OpenTelemetry Authors",
27
38
  "license": "Apache-2.0",
28
39
  "engines": {
29
- "node": "^18.19.0 || >=20.6.0"
40
+ "node": ">=22.15.0"
30
41
  },
31
42
  "files": [
32
- "build/src/**/*.js",
33
- "build/src/**/*.js.map",
34
- "build/src/**/*.d.ts",
35
43
  "LICENSE",
36
- "README.md"
44
+ "README.md",
45
+ "dist"
37
46
  ],
38
47
  "publishConfig": {
39
48
  "access": "public"
40
49
  },
41
50
  "dependencies": {
42
- "@opentelemetry/core": "2.11.0",
51
+ "@opentelemetry/core": "3.0.0-development.1",
43
52
  "yaml": "^2.8.3"
44
53
  },
45
54
  "peerDependencies": {
46
- "@opentelemetry/api": "^1.9.0"
55
+ "@opentelemetry/api": "^1.9.0 || 1.10.0-development.1"
47
56
  },
48
57
  "devDependencies": {
49
- "@opentelemetry/api": "^1.9.0",
58
+ "@opentelemetry/api": "^1.9.0 || 1.10.0-development.1",
50
59
  "@types/mocha": "10.0.10",
51
60
  "@types/node": "18.19.130",
52
61
  "@types/sinon": "17.0.4",
53
62
  "ajv": "^8.0.0",
54
63
  "json-schema-to-typescript": "^15.0.0",
55
64
  "mocha": "11.8.0",
56
- "nyc": "17.1.0",
65
+ "nyc": "18.0.0",
57
66
  "sinon": "18.0.1",
58
67
  "ts-loader": "9.5.7",
59
68
  "typescript": "5.2.2"
60
69
  },
61
70
  "homepage": "https://github.com/open-telemetry/opentelemetry-js/tree/main/experimental/packages/configuration",
62
71
  "sideEffects": false,
63
- "gitHead": "0b72a81636fa476e8f1f1afd2ae0c90a1362194c"
72
+ "gitHead": "83d76963961161511591d5585407d23b5f035a37"
64
73
  }
@@ -1,3 +0,0 @@
1
- import type { ConfigFactory } from './IConfigFactory';
2
- export declare function createConfigFactory(): ConfigFactory;
3
- //# sourceMappingURL=ConfigFactory.d.ts.map
@@ -1,19 +0,0 @@
1
- "use strict";
2
- /*
3
- * Copyright The OpenTelemetry Authors
4
- * SPDX-License-Identifier: Apache-2.0
5
- */
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.createConfigFactory = void 0;
8
- const core_1 = require("@opentelemetry/core");
9
- const EnvironmentConfigFactory_1 = require("./EnvironmentConfigFactory");
10
- const FileConfigFactory_1 = require("./FileConfigFactory");
11
- function createConfigFactory() {
12
- const configFile = (0, core_1.getStringFromEnv)('OTEL_CONFIG_FILE');
13
- if (configFile) {
14
- return new FileConfigFactory_1.FileConfigFactory();
15
- }
16
- return new EnvironmentConfigFactory_1.EnvironmentConfigFactory();
17
- }
18
- exports.createConfigFactory = createConfigFactory;
19
- //# sourceMappingURL=ConfigFactory.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ConfigFactory.js","sourceRoot":"","sources":["../../src/ConfigFactory.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,8CAAuD;AAEvD,yEAAsE;AACtE,2DAAwD;AAExD,SAAgB,mBAAmB;IACjC,MAAM,UAAU,GAAG,IAAA,uBAAgB,EAAC,kBAAkB,CAAC,CAAC;IACxD,IAAI,UAAU,EAAE;QACd,OAAO,IAAI,qCAAiB,EAAE,CAAC;KAChC;IACD,OAAO,IAAI,mDAAwB,EAAE,CAAC;AACxC,CAAC;AAND,kDAMC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { getStringFromEnv } from '@opentelemetry/core';\nimport type { ConfigFactory } from './IConfigFactory';\nimport { EnvironmentConfigFactory } from './EnvironmentConfigFactory';\nimport { FileConfigFactory } from './FileConfigFactory';\n\nexport function createConfigFactory(): ConfigFactory {\n const configFile = getStringFromEnv('OTEL_CONFIG_FILE');\n if (configFile) {\n return new FileConfigFactory();\n }\n return new EnvironmentConfigFactory();\n}\n"]}
@@ -1,15 +0,0 @@
1
- import type { BooleanEnvVar, StringEnvVar } from './EnvReader';
2
- export declare enum SamplerType {
3
- AlwaysOn = "always_on",
4
- AlwaysOff = "always_off",
5
- TraceIdRatio = "traceidratio",
6
- ParentBasedAlwaysOn = "parentbased_always_on",
7
- ParentBasedAlwaysOff = "parentbased_always_off",
8
- ParentBasedTraceIdRatio = "parentbased_traceidratio"
9
- }
10
- export declare const ENV_DEFS: {
11
- readonly OTEL_SDK_DISABLED: BooleanEnvVar;
12
- readonly OTEL_TRACES_SAMPLER: StringEnvVar;
13
- readonly OTEL_TRACES_SAMPLER_ARG: StringEnvVar;
14
- };
15
- //# sourceMappingURL=EnvDefinition.d.ts.map
@@ -1,36 +0,0 @@
1
- "use strict";
2
- /*
3
- * Copyright The OpenTelemetry Authors
4
- * SPDX-License-Identifier: Apache-2.0
5
- */
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.ENV_DEFS = exports.SamplerType = void 0;
8
- var SamplerType;
9
- (function (SamplerType) {
10
- SamplerType["AlwaysOn"] = "always_on";
11
- SamplerType["AlwaysOff"] = "always_off";
12
- SamplerType["TraceIdRatio"] = "traceidratio";
13
- SamplerType["ParentBasedAlwaysOn"] = "parentbased_always_on";
14
- SamplerType["ParentBasedAlwaysOff"] = "parentbased_always_off";
15
- SamplerType["ParentBasedTraceIdRatio"] = "parentbased_traceidratio";
16
- })(SamplerType || (exports.SamplerType = SamplerType = {}));
17
- exports.ENV_DEFS = {
18
- OTEL_SDK_DISABLED: {
19
- key: 'OTEL_SDK_DISABLED',
20
- type: 'boolean',
21
- description: 'Disable the SDK',
22
- defaultValue: false,
23
- },
24
- OTEL_TRACES_SAMPLER: {
25
- key: 'OTEL_TRACES_SAMPLER',
26
- type: 'string',
27
- description: 'Traces sampler',
28
- allowedValues: Object.values(SamplerType),
29
- },
30
- OTEL_TRACES_SAMPLER_ARG: {
31
- key: 'OTEL_TRACES_SAMPLER_ARG',
32
- type: 'string',
33
- description: 'Traces sampler argument',
34
- },
35
- };
36
- //# sourceMappingURL=EnvDefinition.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"EnvDefinition.js","sourceRoot":"","sources":["../../src/EnvDefinition.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAIH,IAAY,WAOX;AAPD,WAAY,WAAW;IACrB,qCAAsB,CAAA;IACtB,uCAAwB,CAAA;IACxB,4CAA6B,CAAA;IAC7B,4DAA6C,CAAA;IAC7C,8DAA+C,CAAA;IAC/C,mEAAoD,CAAA;AACtD,CAAC,EAPW,WAAW,2BAAX,WAAW,QAOtB;AAEY,QAAA,QAAQ,GAAG;IACtB,iBAAiB,EAAE;QACjB,GAAG,EAAE,mBAAmB;QACxB,IAAI,EAAE,SAAS;QACf,WAAW,EAAE,iBAAiB;QAC9B,YAAY,EAAE,KAAK;KACH;IAElB,mBAAmB,EAAE;QACnB,GAAG,EAAE,qBAAqB;QAC1B,IAAI,EAAE,QAAQ;QACd,WAAW,EAAE,gBAAgB;QAC7B,aAAa,EAAE,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC;KAC1B;IAEjB,uBAAuB,EAAE;QACvB,GAAG,EAAE,yBAAyB;QAC9B,IAAI,EAAE,QAAQ;QACd,WAAW,EAAE,yBAAyB;KACvB;CACT,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport type { BooleanEnvVar, StringEnvVar } from './EnvReader';\n\nexport enum SamplerType {\n AlwaysOn = 'always_on',\n AlwaysOff = 'always_off',\n TraceIdRatio = 'traceidratio',\n ParentBasedAlwaysOn = 'parentbased_always_on',\n ParentBasedAlwaysOff = 'parentbased_always_off',\n ParentBasedTraceIdRatio = 'parentbased_traceidratio',\n}\n\nexport const ENV_DEFS = {\n OTEL_SDK_DISABLED: {\n key: 'OTEL_SDK_DISABLED',\n type: 'boolean',\n description: 'Disable the SDK',\n defaultValue: false,\n } as BooleanEnvVar,\n\n OTEL_TRACES_SAMPLER: {\n key: 'OTEL_TRACES_SAMPLER',\n type: 'string',\n description: 'Traces sampler',\n allowedValues: Object.values(SamplerType),\n } as StringEnvVar,\n\n OTEL_TRACES_SAMPLER_ARG: {\n key: 'OTEL_TRACES_SAMPLER_ARG',\n type: 'string',\n description: 'Traces sampler argument',\n } as StringEnvVar,\n} as const;\n"]}
@@ -1,24 +0,0 @@
1
- import { ENV_DEFS } from './EnvDefinition';
2
- /** Base definition shared by all env var types. */
3
- interface EnvVarBase<T> {
4
- key: string;
5
- description: string;
6
- defaultValue?: T;
7
- }
8
- export interface StringEnvVar extends EnvVarBase<string> {
9
- type: 'string';
10
- allowedValues?: readonly string[];
11
- }
12
- export interface BooleanEnvVar extends EnvVarBase<boolean> {
13
- type: 'boolean';
14
- defaultValue: boolean;
15
- }
16
- export type EnvVarDefinition = StringEnvVar | BooleanEnvVar;
17
- type ResolvedType<D extends EnvVarDefinition> = D extends StringEnvVar ? string | undefined : D extends BooleanEnvVar ? boolean : never;
18
- export declare function readEnvVar<D extends EnvVarDefinition>(def: D): ResolvedType<D>;
19
- export type EnvValues = {
20
- [K in keyof typeof ENV_DEFS]: ResolvedType<(typeof ENV_DEFS)[K]>;
21
- };
22
- export declare function readAllEnvVars(): EnvValues;
23
- export {};
24
- //# sourceMappingURL=EnvReader.d.ts.map
@@ -1,60 +0,0 @@
1
- "use strict";
2
- /*
3
- * Copyright The OpenTelemetry Authors
4
- * SPDX-License-Identifier: Apache-2.0
5
- */
6
- Object.defineProperty(exports, "__esModule", { value: true });
7
- exports.readAllEnvVars = exports.readEnvVar = void 0;
8
- const api_1 = require("@opentelemetry/api");
9
- const core_1 = require("@opentelemetry/core");
10
- const EnvDefinition_1 = require("./EnvDefinition");
11
- function readStringEnv(def) {
12
- const value = (0, core_1.getStringFromEnv)(def.key);
13
- if (value == null) {
14
- return def.defaultValue;
15
- }
16
- if (def.allowedValues && !def.allowedValues.includes(value)) {
17
- api_1.diag.warn(`Invalid value "${value}" for ${def.description} (env: ${def.key}). ` +
18
- `Expected one of: ${def.allowedValues.join(', ')}. ` +
19
- (def.defaultValue != null
20
- ? `Falling back to "${def.defaultValue}".`
21
- : 'Value will be ignored.'));
22
- return def.defaultValue;
23
- }
24
- return value;
25
- }
26
- function readBooleanEnv(def) {
27
- const raw = (0, core_1.getStringFromEnv)(def.key)?.trim().toLowerCase();
28
- // Handle the case where the env var is not set (no warning).
29
- if (raw == null || raw === '') {
30
- return def.defaultValue;
31
- }
32
- if (raw === 'true') {
33
- return true;
34
- }
35
- if (raw === 'false') {
36
- return false;
37
- }
38
- // If set to an unrecognized value, warn and fall back to the default.
39
- api_1.diag.warn(`Invalid value "${raw}" for ${def.description} (env: ${def.key}). ` +
40
- `Expected 'true' or 'false'. Falling back to "${def.defaultValue}".`);
41
- return def.defaultValue;
42
- }
43
- function readEnvVar(def) {
44
- switch (def.type) {
45
- case 'string':
46
- return readStringEnv(def);
47
- case 'boolean':
48
- return readBooleanEnv(def);
49
- }
50
- }
51
- exports.readEnvVar = readEnvVar;
52
- function readAllEnvVars() {
53
- const result = {};
54
- for (const [name, def] of Object.entries(EnvDefinition_1.ENV_DEFS)) {
55
- result[name] = readEnvVar(def);
56
- }
57
- return result;
58
- }
59
- exports.readAllEnvVars = readAllEnvVars;
60
- //# sourceMappingURL=EnvReader.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"EnvReader.js","sourceRoot":"","sources":["../../src/EnvReader.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAEH,4CAA0C;AAC1C,8CAAuD;AACvD,mDAA2C;AA2B3C,SAAS,aAAa,CAAC,GAAiB;IACtC,MAAM,KAAK,GAAG,IAAA,uBAAgB,EAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IACxC,IAAI,KAAK,IAAI,IAAI,EAAE;QACjB,OAAO,GAAG,CAAC,YAAY,CAAC;KACzB;IACD,IAAI,GAAG,CAAC,aAAa,IAAI,CAAC,GAAG,CAAC,aAAa,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE;QAC3D,UAAI,CAAC,IAAI,CACP,kBAAkB,KAAK,SAAS,GAAG,CAAC,WAAW,UAAU,GAAG,CAAC,GAAG,KAAK;YACnE,oBAAoB,GAAG,CAAC,aAAa,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI;YACpD,CAAC,GAAG,CAAC,YAAY,IAAI,IAAI;gBACvB,CAAC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AAC7B,CAAC;AAND,wCAMC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n * SPDX-License-Identifier: Apache-2.0\n */\n\nimport { diag } from '@opentelemetry/api';\nimport { getStringFromEnv } from '@opentelemetry/core';\nimport { ENV_DEFS } from './EnvDefinition';\n\n/** Base definition shared by all env var types. */\ninterface EnvVarBase<T> {\n key: string;\n description: string;\n defaultValue?: T;\n}\n\nexport interface StringEnvVar extends EnvVarBase<string> {\n type: 'string';\n allowedValues?: readonly string[];\n}\n\nexport interface BooleanEnvVar extends EnvVarBase<boolean> {\n type: 'boolean';\n defaultValue: boolean;\n}\n\nexport type EnvVarDefinition = StringEnvVar | BooleanEnvVar;\n\ntype ResolvedType<D extends EnvVarDefinition> = D extends StringEnvVar\n ? string | undefined\n : D extends BooleanEnvVar\n ? boolean\n : never;\n\nfunction readStringEnv(def: StringEnvVar): string | undefined {\n const value = getStringFromEnv(def.key);\n if (value == null) {\n return def.defaultValue;\n }\n if (def.allowedValues && !def.allowedValues.includes(value)) {\n diag.warn(\n `Invalid value \"${value}\" for ${def.description} (env: ${def.key}). ` +\n `Expected one of: ${def.allowedValues.join(', ')}. ` +\n (def.defaultValue != null\n ? `Falling back to \"${def.defaultValue}\".`\n : 'Value will be ignored.')\n );\n return def.defaultValue;\n }\n return value;\n}\n\nfunction readBooleanEnv(def: BooleanEnvVar): boolean {\n const raw = getStringFromEnv(def.key)?.trim().toLowerCase();\n // Handle the case where the env var is not set (no warning).\n if (raw == null || raw === '') {\n return def.defaultValue;\n }\n if (raw === 'true') {\n return true;\n }\n if (raw === 'false') {\n return false;\n }\n // If set to an unrecognized value, warn and fall back to the default.\n diag.warn(\n `Invalid value \"${raw}\" for ${def.description} (env: ${def.key}). ` +\n `Expected 'true' or 'false'. Falling back to \"${def.defaultValue}\".`\n );\n return def.defaultValue;\n}\n\nexport function readEnvVar<D extends EnvVarDefinition>(\n def: D\n): ResolvedType<D> {\n switch (def.type) {\n case 'string':\n return readStringEnv(def) as ResolvedType<D>;\n case 'boolean':\n return readBooleanEnv(def) as ResolvedType<D>;\n }\n}\n\nexport type EnvValues = {\n [K in keyof typeof ENV_DEFS]: ResolvedType<(typeof ENV_DEFS)[K]>;\n};\n\nexport function readAllEnvVars(): EnvValues {\n const result = {} as Record<string, unknown>;\n for (const [name, def] of Object.entries(ENV_DEFS)) {\n result[name] = readEnvVar(def);\n }\n return result as EnvValues;\n}\n"]}
@@ -1,19 +0,0 @@
1
- import type { ConfigFactory } from './IConfigFactory';
2
- import type { ConfigurationModel } from './generated/types';
3
- import type { EnvValues } from './EnvReader';
4
- /**
5
- * EnvironmentConfigProvider provides a configuration based on environment variables.
6
- */
7
- export declare class EnvironmentConfigFactory implements ConfigFactory {
8
- private _config;
9
- constructor();
10
- getConfigModel(): ConfigurationModel;
11
- }
12
- export declare function setResources(config: ConfigurationModel): void;
13
- export declare function setAttributeLimits(config: ConfigurationModel): void;
14
- export declare function setPropagators(config: ConfigurationModel): void;
15
- export declare function setSampler(config: ConfigurationModel, env: EnvValues): void;
16
- export declare function setTracerProvider(config: ConfigurationModel, env: EnvValues): void;
17
- export declare function setMeterProvider(config: ConfigurationModel): void;
18
- export declare function setLoggerProvider(config: ConfigurationModel): void;
19
- //# sourceMappingURL=EnvironmentConfigFactory.d.ts.map