Skip to content

Commit

Permalink
Merged
Browse files Browse the repository at this point in the history
  • Loading branch information
davidwitten committed Jun 25, 2020
2 parents dc80b6b + 0788609 commit 4fdce55
Show file tree
Hide file tree
Showing 55 changed files with 1,143 additions and 282 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ Approvers ([@open-telemetry/js-approvers](https://github.com/orgs/open-telemetry
- [Olivier Albertini](https://github.com/OlivierAlbertini), Ville de Montréal
- [Valentin Marchaud](https://github.com/vmarchaud), Open Source Contributor
- [Mark Wolff](https://github.com/markwolff), Microsoft
- [Bartlomiej Obecny](https://github.com/obecny), LightStep
- [Matthew Wear](https://github.com/mwear), LightStep
- [Naseem K. Ullah](https://github.com/naseemkullah), Transit
- [Chengzhong Wu](https://github.com/legendecas), Alibaba
Expand All @@ -143,6 +142,7 @@ Maintainers ([@open-telemetry/js-maintainers](https://github.com/orgs/open-telem

- [Mayur Kale](https://github.com/mayurkale22), Google
- [Daniel Dyla](https://github.com/dyladan), Dynatrace
- [Bartlomiej Obecny](https://github.com/obecny), LightStep

*Find more about the maintainer role in [community repository](https://github.com/open-telemetry/community/blob/master/community-membership.md#maintainer).*

Expand Down
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,17 @@
"author": "OpenTelemetry Authors",
"license": "Apache-2.0",
"devDependencies": {
"@commitlint/cli": "8.3.5",
"@commitlint/config-conventional": "8.3.4",
"@typescript-eslint/eslint-plugin": "3.3.0",
"@typescript-eslint/parser": "3.3.0",
"@commitlint/cli": "9.0.1",
"@commitlint/config-conventional": "9.0.1",
"@typescript-eslint/eslint-plugin": "3.4.0",
"@typescript-eslint/parser": "3.4.0",
"beautify-benchmark": "0.2.4",
"benchmark": "2.1.4",
"eslint": "7.2.0",
"eslint": "7.3.1",
"eslint-config-airbnb-base": "14.2.0",
"eslint-plugin-header": "3.0.0",
"eslint-plugin-import": "2.21.2",
"gh-pages": "3.0.0",
"gh-pages": "3.1.0",
"gts": "2.0.2",
"husky": "4.2.5",
"lerna": "3.22.1",
Expand Down
1 change: 1 addition & 0 deletions packages/opentelemetry-api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
},
"files": [
"build/src/**/*.js",
"build/src/**/*.js.map",
"build/src/**/*.d.ts",
"doc",
"LICENSE",
Expand Down
2 changes: 1 addition & 1 deletion packages/opentelemetry-api/src/trace/tracer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export interface Tracer {
/**
* Returns the current Span from the current context if available.
*
* If there is no Span associated with the current context, `null` is
* If there is no Span associated with the current context, `undefined` is
* returned.
*
* To install a {@link Span} to the current Context use
Expand Down
1 change: 1 addition & 0 deletions packages/opentelemetry-context-async-hooks/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
},
"files": [
"build/src/**/*.js",
"build/src/**/*.js.map",
"build/src/**/*.d.ts",
"doc",
"LICENSE",
Expand Down
1 change: 1 addition & 0 deletions packages/opentelemetry-context-base/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
},
"files": [
"build/src/**/*.js",
"build/src/**/*.js.map",
"build/src/**/*.d.ts",
"doc",
"LICENSE",
Expand Down
3 changes: 2 additions & 1 deletion packages/opentelemetry-context-zone-peer-dep/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
},
"files": [
"build/src/**/*.js",
"build/src/**/*.js.map",
"build/src/**/*.d.ts",
"doc",
"LICENSE",
Expand All @@ -41,7 +42,7 @@
"access": "public"
},
"devDependencies": {
"@babel/core": "7.10.2",
"@babel/core": "7.10.3",
"@types/mocha": "7.0.2",
"@types/node": "14.0.13",
"@types/sinon": "9.0.4",
Expand Down
3 changes: 2 additions & 1 deletion packages/opentelemetry-context-zone/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
},
"files": [
"build/src/**/*.js",
"build/src/**/*.js.map",
"build/src/**/*.d.ts",
"doc",
"LICENSE",
Expand All @@ -38,7 +39,7 @@
"access": "public"
},
"devDependencies": {
"@babel/core": "7.10.2",
"@babel/core": "7.10.3",
"@types/mocha": "7.0.2",
"@types/node": "14.0.13",
"@types/sinon": "9.0.4",
Expand Down
1 change: 1 addition & 0 deletions packages/opentelemetry-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
},
"files": [
"build/src/**/*.js",
"build/src/**/*.js.map",
"build/src/**/*.d.ts",
"doc",
"LICENSE",
Expand Down
10 changes: 10 additions & 0 deletions packages/opentelemetry-core/src/common/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,13 @@ export interface ShimWrapped {
__unwrap: Function;
__original: Function;
}

/**
* An instrumentation library consists of the name and version used to
* obtain a tracer or meter from a provider. This metadata is made available
* on ReadableSpan and MetricRecord for use by the export pipeline.
*/
export interface InstrumentationLibrary {
readonly name: string;
readonly version: string;
}
4 changes: 3 additions & 1 deletion packages/opentelemetry-exporter-collector/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
},
"files": [
"build/src/**/*.js",
"build/src/**/*.js.map",
"build/src/**/*.d.ts",
"build/src/**/*.proto",
"doc",
Expand All @@ -53,7 +54,7 @@
"access": "public"
},
"devDependencies": {
"@babel/core": "7.10.2",
"@babel/core": "7.10.3",
"@types/mocha": "7.0.2",
"@types/node": "14.0.13",
"@types/sinon": "9.0.4",
Expand Down Expand Up @@ -86,6 +87,7 @@
"@opentelemetry/api": "^0.9.0",
"@opentelemetry/core": "^0.9.0",
"@opentelemetry/resources": "^0.9.0",
"@opentelemetry/metrics": "^0.9.0",
"@opentelemetry/tracing": "^0.9.0",
"google-protobuf": "^3.11.4",
"grpc": "^1.24.2"
Expand Down
107 changes: 72 additions & 35 deletions packages/opentelemetry-exporter-collector/src/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,11 +223,10 @@ export function toCollectorExportTraceServiceRequest<
collectorTraceExporterBase: CollectorTraceExporterBase<T>,
name = ''
): opentelemetryProto.collector.trace.v1.ExportTraceServiceRequest {
const spansToBeSent: opentelemetryProto.trace.v1.Span[] = spans.map(span =>
toCollectorSpan(span)
);
const resource: Resource =
spans.length > 0 ? spans[0].resource : Resource.empty();
const groupedSpans: Map<
Resource,
Map<core.InstrumentationLibrary, ReadableSpan[]>
> = groupSpansByResourceAndLibrary(spans);

const additionalAttributes = Object.assign(
{},
Expand All @@ -236,24 +235,45 @@ export function toCollectorExportTraceServiceRequest<
'service.name': collectorTraceExporterBase.serviceName,
}
);
const protoResource: opentelemetryProto.resource.v1.Resource = toCollectorResource(
resource,
additionalAttributes
);
const instrumentationLibrarySpans: opentelemetryProto.trace.v1.InstrumentationLibrarySpans = {
spans: spansToBeSent,
instrumentationLibrary: {
name: name || `${core.SDK_INFO.NAME} - ${core.SDK_INFO.LANGUAGE}`,
version: core.SDK_INFO.VERSION,
},
};
const resourceSpan: opentelemetryProto.trace.v1.ResourceSpans = {
resource: protoResource,
instrumentationLibrarySpans: [instrumentationLibrarySpans],

return {
resourceSpans: toCollectorResourceSpans(groupedSpans, additionalAttributes),
};
}

/**
* Takes an array of spans and groups them by resource and instrumentation
* library
* @param spans spans
*/
export function groupSpansByResourceAndLibrary(
spans: ReadableSpan[]
): Map<Resource, Map<core.InstrumentationLibrary, ReadableSpan[]>> {
return spans.reduce((spanMap, span) => {
//group by resource
let resourceSpans = spanMap.get(span.resource);
if (!resourceSpans) {
resourceSpans = new Map<core.InstrumentationLibrary, ReadableSpan[]>();
spanMap.set(span.resource, resourceSpans);
}
//group by instrumentation library
let libSpans = resourceSpans.get(span.instrumentationLibrary);
if (!libSpans) {
libSpans = new Array<ReadableSpan>();
resourceSpans.set(span.instrumentationLibrary, libSpans);
}
libSpans.push(span);
return spanMap;
}, new Map<Resource, Map<core.InstrumentationLibrary, ReadableSpan[]>>());
}

function toCollectorInstrumentationLibrarySpans(
instrumentationLibrary: core.InstrumentationLibrary,
spans: ReadableSpan[]
): opentelemetryProto.trace.v1.InstrumentationLibrarySpans {
return {
resourceSpans: [resourceSpan],
spans: spans.map(toCollectorSpan),
instrumentationLibrary,
};
}

Expand All @@ -264,24 +284,25 @@ export function toCollectorExportTraceServiceRequest<
export function toCollectorType(
descriptor: MetricDescriptor
): opentelemetryProto.metrics.v1.MetricDescriptorType {
let type: opentelemetryProto.metrics.v1.MetricDescriptorType;
if (descriptor.valueType === apiValueType.INT) {
if (descriptor.monotonic) {
type = opentelemetryProto.metrics.v1.MetricDescriptorType.MONOTONIC_INT64;
} else {
type = opentelemetryProto.metrics.v1.MetricDescriptorType.INT64;
if (
descriptor.metricKind === MetricKind.UP_DOWN_COUNTER ||
descriptor.metricKind === MetricKind.OBSERVER
) {
if (descriptor.valueType === apiValueType.INT) {
return opentelemetryProto.metrics.v1.MetricDescriptorType.INT64;
}
} else if (descriptor.valueType === apiValueType.DOUBLE) {
if (descriptor.monotonic) {
type =
opentelemetryProto.metrics.v1.MetricDescriptorType.MONOTONIC_DOUBLE;
} else {
type = opentelemetryProto.metrics.v1.MetricDescriptorType.DOUBLE;
return opentelemetryProto.metrics.v1.MetricDescriptorType.DOUBLE;
}
// Monotonic counter
else if (descriptor.metricKind === MetricKind.COUNTER) {
if (descriptor.valueType === apiValueType.INT) {
return opentelemetryProto.metrics.v1.MetricDescriptorType.MONOTONIC_INT64;
}
return opentelemetryProto.metrics.v1.MetricDescriptorType.MONOTONIC_DOUBLE;
} else {
type = opentelemetryProto.metrics.v1.MetricDescriptorType.INVALID_TYPE;
// Other types not yet implemented
return opentelemetryProto.metrics.v1.MetricDescriptorType.INVALID_TYPE;
}
return type;
}

/**
Expand All @@ -296,7 +317,7 @@ export function toCollectorTemporality(
} else if (descriptor.metricKind === MetricKind.OBSERVER) {
return opentelemetryProto.metrics.v1.MetricDescriptorTemporality
.INSTANTANEOUS;
} else if (descriptor.metricKind === MetricKind.MEASURE) {
} else if (descriptor.metricKind === MetricKind.VALUE_RECORDER) {
return opentelemetryProto.metrics.v1.MetricDescriptorTemporality.DELTA;
}
return opentelemetryProto.metrics.v1.MetricDescriptorTemporality
Expand Down Expand Up @@ -405,3 +426,19 @@ export function toCollectorExportMetricServiceRequest<
resourceMetrics: [resourceMetric],
};
}

function toCollectorResourceSpans(
groupedSpans: Map<Resource, Map<core.InstrumentationLibrary, ReadableSpan[]>>,
baseAttributes: Attributes
): opentelemetryProto.trace.v1.ResourceSpans[] {
return Array.from(groupedSpans, ([resource, libSpans]) => {
return {
resource: toCollectorResource(resource, baseAttributes),
instrumentationLibrarySpans: Array.from(
libSpans,
([instrumentationLibrary, spans]) =>
toCollectorInstrumentationLibrarySpans(instrumentationLibrary, spans)
),
};
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ import {
mockedReadableSpan,
mockCounter,
mockObserver,
mockedResources,
mockedInstrumentationLibraries,
multiResourceTrace,
multiInstrumentationLibraryTrace,
} from '../helper';
import { Resource } from '@opentelemetry/resources';
import { opentelemetryProto } from '../../src/types';
Expand Down Expand Up @@ -152,5 +156,45 @@ describe('transform', () => {
unit: '2',
});
});
describe('groupSpansByResourceAndLibrary', () => {
it('should group by resource', () => {
const [resource1, resource2] = mockedResources;
const [instrumentationLibrary] = mockedInstrumentationLibraries;
const [span1, span2, span3] = multiResourceTrace;

const expected = new Map([
[resource1, new Map([[instrumentationLibrary, [span1]]])],
[resource2, new Map([[instrumentationLibrary, [span2, span3]]])],
]);

const result = transform.groupSpansByResourceAndLibrary(
multiResourceTrace
);

assert.deepStrictEqual(result, expected);
});

it('should group by instrumentation library', () => {
const [resource] = mockedResources;
const [lib1, lib2] = mockedInstrumentationLibraries;
const [span1, span2, span3] = multiInstrumentationLibraryTrace;

const expected = new Map([
[
resource,
new Map([
[lib1, [span1, span2]],
[lib2, [span3]],
]),
],
]);

const result = transform.groupSpansByResourceAndLibrary(
multiInstrumentationLibraryTrace
);

assert.deepStrictEqual(result, expected);
});
});
});
});
Loading

0 comments on commit 4fdce55

Please sign in to comment.