Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix references
  • Loading branch information
dyladan committed Feb 5, 2025
commit c432a9ed820aadd3602e2a174d7c6dd9fe5d5bb2
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import {
sdkVersion,
serviceName,
} from './util';
import { Resource } from '@opentelemetry/resources';
import { resourceFromAttributes } from '@opentelemetry/resources';
import { AggregationType } from '@opentelemetry/sdk-metrics';

const attributes = {
Expand Down Expand Up @@ -703,14 +703,12 @@ describe('PrometheusSerializer', () => {
it('should serialize resource', () => {
const serializer = new PrometheusSerializer(undefined, true);
const result = serializer['_serializeResource'](
new Resource({
attributes: {
env: 'prod',
hostname: 'myhost',
datacenter: 'sdc',
region: 'europe',
owner: 'frontend',
},
resourceFromAttributes({
env: 'prod',
hostname: 'myhost',
datacenter: 'sdc',
region: 'europe',
owner: 'frontend',
})
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

import { SDK_INFO } from '@opentelemetry/core';
import * as assert from 'assert';
import { IResource, Resource } from '@opentelemetry/resources';
import { IResource } from '@opentelemetry/resources';
import {
SEMRESATTRS_CLOUD_ACCOUNT_ID,
SEMRESATTRS_CLOUD_AVAILABILITY_ZONE,
Expand Down Expand Up @@ -57,7 +57,7 @@ import * as semconv from '@opentelemetry/semantic-conventions';
* @param validations validations for the resource attributes
*/
export const assertCloudResource = (
resource: Resource,
resource: IResource,
validations: {
provider?: string;
accountId?: string;
Expand Down Expand Up @@ -95,7 +95,7 @@ export const assertCloudResource = (
* @param validations validations for the resource attributes
*/
export const assertContainerResource = (
resource: Resource,
resource: IResource,
validations: {
name?: string;
id?: string;
Expand Down Expand Up @@ -133,7 +133,7 @@ export const assertContainerResource = (
* @param validations validations for the resource attributes
*/
export const assertHostResource = (
resource: Resource,
resource: IResource,
validations: {
hostName?: string;
id?: string;
Expand Down Expand Up @@ -184,7 +184,7 @@ export const assertHostResource = (
* @param validations validations for the resource attributes
*/
export const assertK8sResource = (
resource: Resource,
resource: IResource,
validations: {
clusterName?: string;
namespaceName?: string;
Expand Down Expand Up @@ -222,7 +222,7 @@ export const assertK8sResource = (
* @param validations validations for the resource attributes
*/
export const assertTelemetrySDKResource = (
resource: Resource,
resource: IResource,
validations: {
name?: string;
language?: string;
Expand Down Expand Up @@ -295,7 +295,7 @@ export const assertServiceResource = (
* @param validations validations for the resource attributes
*/
export const assertProcessResource = (
resource: Resource,
resource: IResource,
validations: {
pid?: number;
name?: string;
Expand Down Expand Up @@ -332,15 +332,15 @@ export const assertProcessResource = (
*
* @param resource the Resource to validate
*/
export const assertEmptyResource = (resource: Resource) => {
export const assertEmptyResource = (resource: IResource) => {
assert.strictEqual(Object.keys(resource.attributes).length, 0);
};

/**
* Assert that the `resource` has at least one known attribute with the given
* `prefix`. By "known", we mean it is an attribute defined in semconv.
*/
const assertHasOneLabel = (prefix: string, resource: Resource): void => {
const assertHasOneLabel = (prefix: string, resource: IResource): void => {
const semconvModPrefix = `SEMRESATTRS_${prefix.toUpperCase()}_`;
const knownAttrs: Set<string> = new Set(
Object.entries(semconv)
Expand Down
18 changes: 7 additions & 11 deletions experimental/packages/otlp-transformer/test/logs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
import { HrTime, TraceFlags } from '@opentelemetry/api';
import { InstrumentationScope, hexToBinary } from '@opentelemetry/core';
import { Resource } from '@opentelemetry/resources';
import { IResource, resourceFromAttributes } from '@opentelemetry/resources';
import * as assert from 'assert';
import { ReadableLogRecord } from '@opentelemetry/sdk-logs';
import { SeverityNumber } from '@opentelemetry/api-logs';
Expand Down Expand Up @@ -143,8 +143,8 @@ function createExpectedLogProtobuf(): IExportLogsServiceRequest {
}

describe('Logs', () => {
let resource_1: Resource;
let resource_2: Resource;
let resource_1: IResource;
let resource_2: IResource;
let scope_1: InstrumentationScope;
let scope_2: InstrumentationScope;

Expand All @@ -165,15 +165,11 @@ describe('Logs', () => {
let log_2_1_1: ReadableLogRecord;

beforeEach(() => {
resource_1 = new Resource({
attributes: {
'resource-attribute': 'some attribute value',
},
resource_1 = resourceFromAttributes({
'resource-attribute': 'some attribute value',
});
resource_2 = new Resource({
attributes: {
'resource-attribute': 'another attribute value',
},
resource_2 = resourceFromAttributes({
'resource-attribute': 'another attribute value',
});
scope_1 = {
name: 'scope_name_1',
Expand Down
8 changes: 3 additions & 5 deletions experimental/packages/otlp-transformer/test/metrics.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/
import { ValueType } from '@opentelemetry/api';
import { Resource } from '@opentelemetry/resources';
import { resourceFromAttributes } from '@opentelemetry/resources';
import {
AggregationTemporality,
DataPointType,
Expand Down Expand Up @@ -302,10 +302,8 @@ describe('Metrics', () => {
}

function createResourceMetrics(metricData: MetricData[]): ResourceMetrics {
const resource = new Resource({
attributes: {
'resource-attribute': 'resource attribute value',
},
const resource = resourceFromAttributes({
'resource-attribute': 'resource attribute value',
});
return {
resource: resource,
Expand Down
10 changes: 4 additions & 6 deletions experimental/packages/otlp-transformer/test/trace.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import * as root from '../src/generated/root';
import { SpanKind, SpanStatusCode, TraceFlags } from '@opentelemetry/api';
import { TraceState, hexToBinary } from '@opentelemetry/core';
import { Resource } from '@opentelemetry/resources';
import { IResource, resourceFromAttributes } from '@opentelemetry/resources';
import { ReadableSpan } from '@opentelemetry/sdk-trace-base';
import * as assert from 'assert';
import { toBase64 } from './utils';
Expand Down Expand Up @@ -227,14 +227,12 @@ function createExpectedSpanProtobuf() {
}

describe('Trace', () => {
let resource: Resource;
let resource: IResource;
let span: ReadableSpan;

beforeEach(() => {
resource = new Resource({
attributes: {
'resource-attribute': 'resource attribute value',
},
resource = resourceFromAttributes({
'resource-attribute': 'resource attribute value',
});
span = {
spanContext: () => ({
Expand Down
8 changes: 3 additions & 5 deletions packages/opentelemetry-exporter-jaeger/test/jaeger.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import * as api from '@opentelemetry/api';
import { ThriftProcess } from '../src/types';
import { ReadableSpan } from '@opentelemetry/sdk-trace-base';
import { TraceFlags } from '@opentelemetry/api';
import { Resource } from '@opentelemetry/resources';
import { resourceFromAttributes } from '@opentelemetry/resources';
import * as nock from 'nock';
import { SEMRESATTRS_SERVICE_NAME } from '@opentelemetry/semantic-conventions';

Expand All @@ -46,10 +46,8 @@ describe('JaegerExporter', () => {
links: [],
events: [],
duration: [32, 800000000],
resource: new Resource({
attributes: {
[SEMRESATTRS_SERVICE_NAME]: 'opentelemetry',
},
resource: resourceFromAttributes({
[SEMRESATTRS_SERVICE_NAME]: 'opentelemetry',
}),
instrumentationScope: {
name: 'default',
Expand Down
25 changes: 12 additions & 13 deletions packages/opentelemetry-exporter-jaeger/test/transform.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@
import * as assert from 'assert';
import { spanToThrift } from '../src/transform';
import { ReadableSpan } from '@opentelemetry/sdk-trace-base';
import { EMPTY_RESOURCE } from '@opentelemetry/resources';
import {
EMPTY_RESOURCE,
resourceFromAttributes,
} from '@opentelemetry/resources';
import * as api from '@opentelemetry/api';
import { ThriftUtils, Utils, ThriftReferenceType } from '../src/types';
import { hrTimeToMicroseconds } from '@opentelemetry/core';
Expand Down Expand Up @@ -73,12 +76,10 @@ describe('transform', () => {
},
],
duration: [32, 800000000],
resource: new Resource({
attributes: {
service: 'ui',
version: 1,
cost: 112.12,
},
resource: resourceFromAttributes({
service: 'ui',
version: 1,
cost: 112.12,
}),
instrumentationScope: {
name: 'default',
Expand Down Expand Up @@ -358,12 +359,10 @@ describe('transform', () => {
},
],
duration: [32, 800000000],
resource: new Resource({
attributes: {
service: 'ui',
version: 1,
cost: 112.12,
},
resource: resourceFromAttributes({
service: 'ui',
version: 1,
cost: 112.12,
}),
instrumentationScope: {
name: 'default',
Expand Down
12 changes: 5 additions & 7 deletions packages/opentelemetry-exporter-zipkin/test/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@

import { TraceFlags, SpanStatusCode } from '@opentelemetry/api';
import { ReadableSpan } from '@opentelemetry/sdk-trace-base';
import { Resource } from '@opentelemetry/resources';
import * as assert from 'assert';
import { Span } from '../src/types';
import { resourceFromAttributes } from '@opentelemetry/resources';

export const mockedReadableSpan: ReadableSpan = {
name: 'documentFetch',
Expand All @@ -39,12 +39,10 @@ export const mockedReadableSpan: ReadableSpan = {
links: [],
events: [],
duration: [0, 8885000],
resource: new Resource({
attributes: {
service: 'ui',
version: 1,
cost: 112.12,
},
resource: resourceFromAttributes({
service: 'ui',
version: 1,
cost: 112.12,
}),
instrumentationScope: { name: 'default', version: '0.0.1' },
droppedAttributesCount: 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
ExportResultCode,
} from '@opentelemetry/core';
import * as api from '@opentelemetry/api';
import { EMPTY_RESOURCE } from '@opentelemetry/resources';
import { EMPTY_RESOURCE, resourceFromAttributes } from '@opentelemetry/resources';
import { ZipkinExporter } from '../../src';
import * as zipkinTypes from '../../src/types';
import { TraceFlags } from '@opentelemetry/api';
Expand Down Expand Up @@ -384,8 +384,8 @@ describe('Zipkin Exporter - node', () => {
attributes: { key3: 'value3' },
},
],
resource: new Resource({
attributes: { [SEMRESATTRS_SERVICE_NAME]: resource_service_name },
resource: resourceFromAttributes({
[SEMRESATTRS_SERVICE_NAME]: resource_service_name,
}),
instrumentationScope: { name: 'default', version: '0.0.1' },
droppedAttributesCount: 0,
Expand All @@ -410,8 +410,8 @@ describe('Zipkin Exporter - node', () => {
attributes: {},
links: [],
events: [],
resource: new Resource({
attributes: { [SEMRESATTRS_SERVICE_NAME]: resource_service_name_prime },
resource: resourceFromAttributes({
[SEMRESATTRS_SERVICE_NAME]: resource_service_name_prime,
}),
instrumentationScope: { name: 'default', version: '0.0.1' },
droppedAttributesCount: 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,18 @@
* limitations under the License.
*/
import * as sinon from 'sinon';
import { processDetector, Resource } from '../../../src';
import { processDetector } from '../../../src';
import { describeBrowser } from '../../util';
import { assertEmptyResource } from '../../util/resource-assertions';
import { resourceFromDetectedResource } from '../../../src/Resource';

describeBrowser('processDetector() on web browser', () => {
afterEach(() => {
sinon.restore();
});

it('should return empty resource', async () => {
const resource = new Resource(processDetector.detect());
const resource = resourceFromDetectedResource(processDetector.detect());
assertEmptyResource(resource);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { Resource } from '../../../src';
import { browserDetector } from '../../../src/detectors/BrowserDetector';
import { resourceFromDetectedResource } from '../../../src/Resource';
import { describeNode } from '../../util';
import { assertEmptyResource } from '../../util/resource-assertions';

describeNode('browserDetector()', () => {
it('should return empty resources if window.document is missing', async () => {
const resource = new Resource(browserDetector.detect());
const resource = resourceFromDetectedResource(browserDetector.detect());
assertEmptyResource(resource);
});
});
Loading
Loading