-
Notifications
You must be signed in to change notification settings - Fork 994
feat(collector-exporter): allow configuration from env #2099 #2101
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,63 @@ | ||||||||||
| /* | ||||||||||
| * Copyright The OpenTelemetry Authors | ||||||||||
| * | ||||||||||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||||||||||
| * you may not use this file except in compliance with the License. | ||||||||||
| * You may obtain a copy of the License at | ||||||||||
| * | ||||||||||
| * https://www.apache.org/licenses/LICENSE-2.0 | ||||||||||
| * | ||||||||||
| * Unless required by applicable law or agreed to in writing, software | ||||||||||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||||||||||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||||||||
| * See the License for the specific language governing permissions and | ||||||||||
| * limitations under the License. | ||||||||||
| */ | ||||||||||
| import { Baggage, baggageEntryMetadataFromString } from '@opentelemetry/api'; | ||||||||||
|
|
||||||||||
| export const KEY_PAIR_SEPARATOR = '='; | ||||||||||
| export const PROPERTIES_SEPARATOR = ';'; | ||||||||||
| export const ITEMS_SEPARATOR = ','; | ||||||||||
|
|
||||||||||
| // Name of the http header used to propagate the baggage | ||||||||||
| export const BAGGAGE_HEADER = 'baggage'; | ||||||||||
| // Maximum number of name-value pairs allowed by w3c spec | ||||||||||
| export const MAX_NAME_VALUE_PAIRS = 180; | ||||||||||
| // Maximum number of bytes per a single name-value pair allowed by w3c spec | ||||||||||
| export const MAX_PER_NAME_VALUE_PAIRS = 4096; | ||||||||||
| // Maximum total length of all name-value pairs allowed by w3c spec | ||||||||||
| export const MAX_TOTAL_LENGTH = 8192; | ||||||||||
|
|
||||||||||
| export const serializeKeyPairs = (keyPairs: string[]) => { | ||||||||||
| return keyPairs.reduce((hValue: string, current: string) => { | ||||||||||
| const value = `${hValue}${hValue !== '' ? ITEMS_SEPARATOR : ''}${current}`; | ||||||||||
| return value.length > MAX_TOTAL_LENGTH ? hValue : value; | ||||||||||
| }, ''); | ||||||||||
| }; | ||||||||||
|
|
||||||||||
| export const getKeyPairs = (baggage: Baggage): string[] => { | ||||||||||
| return baggage | ||||||||||
| .getAllEntries() | ||||||||||
| .map( | ||||||||||
| ([key, value]) => | ||||||||||
| `${encodeURIComponent(key)}=${encodeURIComponent(value.value)}` | ||||||||||
| ); | ||||||||||
| }; | ||||||||||
|
|
||||||||||
| export const parsePairKeyValue = (entry: string) => { | ||||||||||
| const valueProps = entry.split(PROPERTIES_SEPARATOR); | ||||||||||
| if (valueProps.length <= 0) return; | ||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit / suggestions
Suggested change
|
||||||||||
| const keyPairPart = valueProps.shift(); | ||||||||||
| if (!keyPairPart) return; | ||||||||||
| const keyPair = keyPairPart.split(KEY_PAIR_SEPARATOR); | ||||||||||
| if (keyPair.length !== 2) return; | ||||||||||
| const key = decodeURIComponent(keyPair[0].trim()); | ||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: line space |
||||||||||
| const value = decodeURIComponent(keyPair[1].trim()); | ||||||||||
| let metadata; | ||||||||||
| if (valueProps.length > 0) { | ||||||||||
| metadata = baggageEntryMetadataFromString( | ||||||||||
| valueProps.join(PROPERTIES_SEPARATOR) | ||||||||||
| ); | ||||||||||
| } | ||||||||||
| return { key, value, metadata }; | ||||||||||
| }; | ||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -69,6 +69,12 @@ export type ENVIRONMENT = { | |
| OTEL_EXPORTER_JAEGER_USER?: string; | ||
| OTEL_LOG_LEVEL?: DiagLogLevel; | ||
| OTEL_RESOURCE_ATTRIBUTES?: string; | ||
| OTEL_EXPORTER_OTLP_ENDPOINT?: string; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. pls keep it in alphabetical order so it is easier to find / add new one |
||
| OTEL_EXPORTER_OTLP_TRACES_ENDPOINT?: string; | ||
| OTEL_EXPORTER_OTLP_METRICS_ENDPOINT?: string; | ||
| OTEL_EXPORTER_OTLP_HEADERS?: string; | ||
| OTEL_EXPORTER_OTLP_TRACES_HEADERS?: string; | ||
| OTEL_EXPORTER_OTLP_METRICS_HEADERS?: string; | ||
| } & ENVIRONMENT_NUMBERS & | ||
| ENVIRONMENT_LISTS; | ||
|
|
||
|
|
@@ -102,6 +108,12 @@ export const DEFAULT_ENVIRONMENT: Required<ENVIRONMENT> = { | |
| OTEL_SPAN_ATTRIBUTE_COUNT_LIMIT: 1000, | ||
| OTEL_SPAN_EVENT_COUNT_LIMIT: 1000, | ||
| OTEL_SPAN_LINK_COUNT_LIMIT: 1000, | ||
| OTEL_EXPORTER_OTLP_ENDPOINT: '', | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. pls keep it in alphabetical order so it is easier to find / add new one |
||
| OTEL_EXPORTER_OTLP_TRACES_ENDPOINT: '', | ||
| OTEL_EXPORTER_OTLP_METRICS_ENDPOINT: '', | ||
| OTEL_EXPORTER_OTLP_HEADERS: '', | ||
| OTEL_EXPORTER_OTLP_TRACES_HEADERS: '', | ||
| OTEL_EXPORTER_OTLP_METRICS_HEADERS: '', | ||
| }; | ||
|
|
||
| /** | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,12 +19,8 @@ import { | |
| toCollectorExportMetricServiceRequest, | ||
| } from '@opentelemetry/exporter-collector'; | ||
| import { MetricRecord, MetricExporter } from '@opentelemetry/metrics'; | ||
| import { CollectorExporterConfigNode, ServiceClientType } from './types'; | ||
| import { CollectorExporterNodeBase } from './CollectorExporterNodeBase'; | ||
|
|
||
| const DEFAULT_SERVICE_NAME = 'collector-metric-exporter'; | ||
| const DEFAULT_COLLECTOR_URL = 'localhost:4317'; | ||
|
|
||
| /** | ||
| * Collector Metric Exporter for Node | ||
| */ | ||
|
|
@@ -47,22 +43,15 @@ export class CollectorMetricExporter | |
| ); | ||
| } | ||
|
|
||
| getDefaultUrl(config: CollectorExporterConfigNode): string { | ||
| if (!config.url) { | ||
| return DEFAULT_COLLECTOR_URL; | ||
| } | ||
| return config.url; | ||
| } | ||
|
|
||
| getDefaultServiceName(config: CollectorExporterConfigNode): string { | ||
| return config.serviceName || DEFAULT_SERVICE_NAME; | ||
| getServiceProtoPath(): string { | ||
| return 'opentelemetry/proto/collector/metrics/v1/metrics_service.proto'; | ||
| } | ||
|
|
||
| getServiceClientType() { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hmm not sure why was this removed, it will be still needed to differentiate between metrics and traces - it is metrics and you changed this to be traces ? |
||
| return ServiceClientType.METRICS; | ||
| getExporterType() { | ||
| return 'trace' as const; | ||
| } | ||
|
|
||
| getServiceProtoPath(): string { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is also needed to correctly import the appropriate proto definitions. |
||
| return 'opentelemetry/proto/collector/metrics/v1/metrics_service.proto'; | ||
| getProtocol() { | ||
| return 'grpc' as const; | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if you split this already what if you keep all const in separate file ?
constants.tsfor example ?and then later in code instead of
you will have for example