Skip to content
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

chore: set default service name #2227

Merged
merged 10 commits into from
Jun 1, 2021
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import { CollectorExporterNodeBase } from './CollectorExporterNodeBase';
import { getEnv } from '@opentelemetry/core';
import { validateAndNormalizeUrl } from './util';

const DEFAULT_SERVICE_NAME = 'collector-metric-exporter';
const DEFAULT_COLLECTOR_URL = 'localhost:4317';

/**
Expand Down Expand Up @@ -59,10 +58,6 @@ export class CollectorMetricExporter
: DEFAULT_COLLECTOR_URL;
}

getDefaultServiceName(config: CollectorExporterConfigNode): string {
return config.serviceName || DEFAULT_SERVICE_NAME;
}

getServiceClientType() {
return ServiceClientType.METRICS;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import { CollectorExporterConfigNode, ServiceClientType } from './types';
import { getEnv } from '@opentelemetry/core';
import { validateAndNormalizeUrl } from './util';

const DEFAULT_SERVICE_NAME = 'collector-trace-exporter';
const DEFAULT_COLLECTOR_URL = 'localhost:4317';

/**
Expand Down Expand Up @@ -52,10 +51,6 @@ export class CollectorTraceExporter
: DEFAULT_COLLECTOR_URL;
}

getDefaultServiceName(config: CollectorExporterConfigNode): string {
return config.serviceName || DEFAULT_SERVICE_NAME;
}

getServiceClientType() {
return ServiceClientType.SPANS;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ const testCollectorMetricExporter = (params: TestParams) =>
collectorExporter = new CollectorMetricExporter({
url: 'grpcs://' + address,
credentials,
serviceName: 'basic-service',
metadata: params.metadata,
});
// Overwrites the start time to make tests consistent
Expand Down Expand Up @@ -169,7 +168,6 @@ const testCollectorMetricExporter = (params: TestParams) =>
// Need to stub/spy on the underlying logger as the 'diag' instance is global
const spyLoggerWarn = sinon.stub(diag, 'warn');
collectorExporter = new CollectorMetricExporter({
serviceName: 'basic-service',
url: `http://${address}`,
headers: {
foo: 'bar',
Expand All @@ -181,7 +179,6 @@ const testCollectorMetricExporter = (params: TestParams) =>
it('should warn about path in url', () => {
const spyLoggerWarn = sinon.stub(diag, 'warn');
collectorExporter = new CollectorMetricExporter({
serviceName: 'basic-service',
url: `http://${address}/v1/metrics`
});
const args = spyLoggerWarn.args[0];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ const testCollectorExporter = (params: TestParams) =>
)
: undefined;
collectorExporter = new CollectorTraceExporter({
serviceName: 'basic-service',
url: 'grpcs://' + address,
credentials,
metadata: params.metadata,
Expand All @@ -146,7 +145,6 @@ const testCollectorExporter = (params: TestParams) =>
// Need to stub/spy on the underlying logger as the 'diag' instance is global
const spyLoggerWarn = sinon.stub(diag, 'warn');
collectorExporter = new CollectorTraceExporter({
serviceName: 'basic-service',
url: `http://${address}`,
headers: {
foo: 'bar',
Expand All @@ -158,7 +156,6 @@ const testCollectorExporter = (params: TestParams) =>
it('should warn about path in url', () => {
const spyLoggerWarn = sinon.stub(diag, 'warn');
collectorExporter = new CollectorTraceExporter({
serviceName: 'basic-service',
url: `http://${address}/v1/trace`,
});
const args = spyLoggerWarn.args[0];
Expand Down
28 changes: 25 additions & 3 deletions packages/opentelemetry-exporter-collector-grpc/test/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { Resource } from '@opentelemetry/resources';
import { ReadableSpan } from '@opentelemetry/tracing';
import * as assert from 'assert';
import * as grpc from '@grpc/grpc-js';
import { VERSION } from '@opentelemetry/core';

const meterProvider = new metrics.MeterProvider({
interval: 30000,
Expand Down Expand Up @@ -154,11 +155,11 @@ export const mockedReadableSpan: ReadableSpan = {
},
],
duration: [0, 8885000],
resource: new Resource({
resource: Resource.default().merge(new Resource({
service: 'ui',
version: 1,
cost: 112.12,
}),
})),
instrumentationLibrary: { name: 'default', version: '0.0.1' },
};

Expand Down Expand Up @@ -408,10 +409,31 @@ export function ensureResourceIsCorrect(
{
key: 'service.name',
value: {
stringValue: 'basic-service',
stringValue: '@opentelemetry/exporter-collector-grpc',
value: 'stringValue',
},
},
{
"key": "telemetry.sdk.language",
"value": {
"stringValue": "nodejs",
"value": "stringValue"
}
},
{
"key": "telemetry.sdk.name",
"value": {
"stringValue": "opentelemetry",
"value": "stringValue"
}
},
{
"key": "telemetry.sdk.version",
"value": {
"stringValue": VERSION,
"value": "stringValue"
}
},
{
key: 'service',
value: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import { ServiceClientType } from './types';
import { CollectorExporterNodeBase } from './CollectorExporterNodeBase';
import { getEnv, baggageUtils } from '@opentelemetry/core';

const DEFAULT_SERVICE_NAME = 'collector-metric-exporter';
const DEFAULT_COLLECTOR_URL = 'http://localhost:4317/v1/metrics';

/**
Expand Down Expand Up @@ -69,10 +68,6 @@ export class CollectorMetricExporter
: DEFAULT_COLLECTOR_URL;
}

getDefaultServiceName(config: CollectorExporterNodeConfigBase): string {
return config.serviceName || DEFAULT_SERVICE_NAME;
}

getServiceClientType() {
return ServiceClientType.METRICS;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import {
import { ServiceClientType } from './types';
import { getEnv, baggageUtils } from '@opentelemetry/core';

const DEFAULT_SERVICE_NAME = 'collector-trace-exporter';
const DEFAULT_COLLECTOR_URL = 'http://localhost:4317/v1/traces';

/**
Expand Down Expand Up @@ -62,10 +61,6 @@ export class CollectorTraceExporter
: DEFAULT_COLLECTOR_URL;
}

getDefaultServiceName(config: CollectorExporterNodeConfigBase): string {
return config.serviceName || DEFAULT_SERVICE_NAME;
}

getServiceClientType() {
return ServiceClientType.SPANS;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ describe('CollectorMetricExporter - node with proto over http', () => {
foo: 'bar',
},
hostname: 'foo',
serviceName: 'bar',
attributes: {},
url: 'http://foo.bar.com',
keepAlive: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ describe('CollectorTraceExporter - node with proto over http', () => {
foo: 'bar',
},
hostname: 'foo',
serviceName: 'bar',
attributes: {},
url: 'http://foo.bar.com',
keepAlive: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ export abstract class CollectorExporterBase<
ExportItem,
ServiceRequest
> {
public readonly serviceName: string;
public readonly url: string;
public readonly hostname: string | undefined;
public readonly attributes?: SpanAttributes;
Expand All @@ -43,7 +42,6 @@ export abstract class CollectorExporterBase<
* @param config
*/
constructor(config: T = {} as T) {
this.serviceName = this.getDefaultServiceName(config);
this.url = this.getDefaultUrl(config);
if (typeof config.hostname === 'string') {
this.hostname = config.hostname;
Expand Down Expand Up @@ -140,6 +138,5 @@ export abstract class CollectorExporterBase<
onError: (error: CollectorExporterError) => void
): void;
abstract getDefaultUrl(config: T): string;
abstract getDefaultServiceName(config: T): string;
abstract convert(objects: ExportItem[]): ServiceRequest;
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import { toCollectorExportMetricServiceRequest } from '../../transformMetrics';
import { getEnv, baggageUtils } from '@opentelemetry/core';

const DEFAULT_COLLECTOR_URL = 'http://localhost:55681/v1/metrics';
const DEFAULT_SERVICE_NAME = 'collector-metric-exporter';

/**
* Collector Metric Exporter for Web
Expand Down Expand Up @@ -65,8 +64,4 @@ export class CollectorMetricExporter
? getEnv().OTEL_EXPORTER_OTLP_ENDPOINT
: DEFAULT_COLLECTOR_URL;
}

getDefaultServiceName(config: CollectorExporterConfigBase): string {
return config.serviceName || DEFAULT_SERVICE_NAME;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import { toCollectorExportTraceServiceRequest } from '../../transform';
import * as collectorTypes from '../../types';
import { getEnv, baggageUtils } from '@opentelemetry/core';

const DEFAULT_SERVICE_NAME = 'collector-trace-exporter';
const DEFAULT_COLLECTOR_URL = 'http://localhost:55681/v1/traces';

/**
Expand Down Expand Up @@ -57,8 +56,4 @@ export class CollectorTraceExporter
? getEnv().OTEL_EXPORTER_OTLP_ENDPOINT
: DEFAULT_COLLECTOR_URL;
}

getDefaultServiceName(config: CollectorExporterConfigBase): string {
return config.serviceName ?? DEFAULT_SERVICE_NAME;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import { CollectorExporterNodeBase } from './CollectorExporterNodeBase';
import { toCollectorExportMetricServiceRequest } from '../../transformMetrics';
import { getEnv, baggageUtils } from '@opentelemetry/core';

const DEFAULT_SERVICE_NAME = 'collector-metric-exporter';
const DEFAULT_COLLECTOR_URL = 'http://localhost:55681/v1/metrics';

/**
Expand Down Expand Up @@ -65,8 +64,4 @@ export class CollectorMetricExporter
? getEnv().OTEL_EXPORTER_OTLP_ENDPOINT
: DEFAULT_COLLECTOR_URL;
}

getDefaultServiceName(config: CollectorExporterNodeConfigBase): string {
return config.serviceName || DEFAULT_SERVICE_NAME;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import * as collectorTypes from '../../types';
import { toCollectorExportTraceServiceRequest } from '../../transform';
import { getEnv, baggageUtils } from '@opentelemetry/core';

const DEFAULT_SERVICE_NAME = 'collector-trace-exporter';
const DEFAULT_COLLECTOR_URL = 'http://localhost:55681/v1/traces';

/**
Expand Down Expand Up @@ -58,8 +57,4 @@ export class CollectorTraceExporter
? getEnv().OTEL_EXPORTER_OTLP_ENDPOINT
: DEFAULT_COLLECTOR_URL;
}

getDefaultServiceName(config: CollectorExporterNodeConfigBase): string {
return config.serviceName || DEFAULT_SERVICE_NAME;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -285,10 +285,7 @@ export function toCollectorExportTraceServiceRequest<

const additionalAttributes = Object.assign(
{},
collectorTraceExporterBase.attributes,
{
'service.name': collectorTraceExporterBase.serviceName,
}
collectorTraceExporterBase.attributes
);

return {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,7 @@ export function toCollectorExportMetricServiceRequest<
> = groupMetricsByResourceAndLibrary(metrics);
const additionalAttributes = Object.assign(
{},
collectorExporterBase.attributes,
{
'service.name': collectorExporterBase.serviceName,
}
collectorExporterBase.attributes
);
return {
resourceMetrics: toCollectorResourceMetrics(
Expand Down
1 change: 0 additions & 1 deletion packages/opentelemetry-exporter-collector/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,6 @@ export interface ExportServiceError {
export interface CollectorExporterConfigBase {
headers?: Partial<Record<string, unknown>>;
hostname?: string;
serviceName?: string;
attributes?: SpanAttributes;
url?: string;
concurrencyLimit?: number;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,6 @@ describe('CollectorMetricExporter - web', () => {
beforeEach(() => {
collectorExporter = new CollectorMetricExporter({
url: 'http://foo.bar.com',
serviceName: 'bar',
});
// Overwrites the start time to make tests consistent
Object.defineProperty(collectorExporter, '_startTime', {
Expand Down Expand Up @@ -193,7 +192,6 @@ describe('CollectorMetricExporter - web', () => {
(window.navigator as any).sendBeacon = false;
collectorExporter = new CollectorMetricExporter({
url: 'http://foo.bar.com',
serviceName: 'bar',
});
// Overwrites the start time to make tests consistent
Object.defineProperty(collectorExporter, '_startTime', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ describe('CollectorTraceExporter - web', () => {
beforeEach(() => {
collectorExporterConfig = {
hostname: 'foo',
serviceName: 'bar',
attributes: {},
url: 'http://foo.bar.com',
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,6 @@ class CollectorMetricExporter extends CollectorExporterBase<
getDefaultUrl(config: CollectorExporterConfig) {
return config.url || '';
}
getDefaultServiceName(config: CollectorExporterConfig): string {
return config.serviceName || 'collector-metric-exporter';
}
convert(
metrics: MetricRecord[]
): collectorTypes.opentelemetryProto.collector.metrics.v1.ExportMetricsServiceRequest {
Expand All @@ -67,7 +64,6 @@ describe('CollectorMetricExporter - common', () => {
onInitSpy = sinon.stub(CollectorMetricExporter.prototype, 'onInit');
collectorExporterConfig = {
hostname: 'foo',
serviceName: 'bar',
attributes: {},
url: 'http://foo.bar.com',
};
Expand Down Expand Up @@ -100,10 +96,6 @@ describe('CollectorMetricExporter - common', () => {
assert.strictEqual(collectorExporter.hostname, 'foo');
});

it('should set serviceName', () => {
assert.strictEqual(collectorExporter.serviceName, 'bar');
});

it('should set url', () => {
assert.strictEqual(collectorExporter.url, 'http://foo.bar.com');
});
Expand All @@ -113,13 +105,6 @@ describe('CollectorMetricExporter - common', () => {
beforeEach(() => {
collectorExporter = new CollectorMetricExporter();
});

it('should set default serviceName', () => {
assert.strictEqual(
collectorExporter.serviceName,
'collector-metric-exporter'
);
});
});
});

Expand Down Expand Up @@ -201,7 +186,6 @@ describe('CollectorMetricExporter - common', () => {
);
collectorExporterConfig = {
hostname: 'foo',
serviceName: 'bar',
attributes: {},
url: 'http://foo.bar.com',
};
Expand Down
Loading