Skip to content

Commit

Permalink
feat: Add types for Collector Metric Exporter (open-telemetry#1271)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidwitten authored Jul 6, 2020
1 parent 46ce535 commit 413edb5
Show file tree
Hide file tree
Showing 6 changed files with 140 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import { CollectorTraceExporterBase } from '../../CollectorTraceExporterBase';
import { ReadableSpan } from '@opentelemetry/tracing';
import { toCollectorExportTraceServiceRequest } from '../../transform';
import { CollectorExporterConfigBrowser } from '../../types';
import { CollectorExporterConfigBrowser } from './types';
import * as collectorTypes from '../../types';

const DEFAULT_COLLECTOR_URL = 'http://localhost:55680/v1/trace';
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* 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 { CollectorExporterConfigBase } from '../../types';

/**
* Collector Exporter Config for Web
*/
export interface CollectorExporterConfigBrowser
extends CollectorExporterConfigBase {
headers?: { [key: string]: string };
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,13 @@ import * as collectorTypes from '../../types';

import { ReadableSpan } from '@opentelemetry/tracing';
import { CollectorTraceExporterBase } from '../../CollectorTraceExporterBase';
import { CollectorExporterError } from '../../types';
import { toCollectorExportTraceServiceRequest } from '../../transform';
import {
CollectorExporterError,
GRPCSpanQueueItem,
ServiceClient,
CollectorExporterConfigNode,
} from '../../types';
import { toCollectorExportTraceServiceRequest } from '../../transform';
import { GRPCSpanQueueItem, ServiceClient } from './types';
} from './types';
import { removeProtocol } from './util';

const DEFAULT_COLLECTOR_URL = 'localhost:55680';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@

import * as grpc from 'grpc';
import { ReadableSpan } from '@opentelemetry/tracing';
import { CollectorExporterError } from '../../types';
import {
CollectorExporterError,
CollectorExporterConfigBase,
} from '../../types';

/**
* Queue item to be used to save temporary spans in case the GRPC service
Expand All @@ -38,3 +41,12 @@ export interface ServiceClient extends grpc.Client {
callback: Function
) => {};
}

/**
* Collector Exporter Config for Node
*/
export interface CollectorExporterConfigNode
extends CollectorExporterConfigBase {
credentials?: grpc.ChannelCredentials;
metadata?: grpc.Metadata;
}
112 changes: 94 additions & 18 deletions packages/opentelemetry-exporter-collector/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

import { SpanKind, Logger, Attributes } from '@opentelemetry/api';
import * as api from '@opentelemetry/api';
import * as grpc from 'grpc';

// header to prevent instrumentation on request
export const OT_REQUEST_HEADER = 'x-opentelemetry-outgoing-request';
Expand All @@ -42,6 +41,100 @@ export namespace opentelemetryProto {
}
}

export namespace metrics.v1 {
export interface Metric {
metricDescriptor: opentelemetryProto.metrics.v1.MetricDescriptor;
int64DataPoints?: opentelemetryProto.metrics.v1.Int64DataPoint[];
doubleDataPoints?: opentelemetryProto.metrics.v1.DoubleDataPoint[];
histogramDataPoints?: opentelemetryProto.metrics.v1.HistogramDataPoint[];
summaryDataPoints?: opentelemetryProto.metrics.v1.SummaryDataPoint[];
}

export interface Int64DataPoint {
labels: opentelemetryProto.common.v1.StringKeyValue[];
startTimeUnixNano: number;
timeUnixNano: number;
value: number;
}

export interface DoubleDataPoint {
labels: opentelemetryProto.common.v1.StringKeyValue[];
startTimeUnixNano: number;
timeUnixNano: number;
value: number;
}

export interface HistogramDataPoint {
labels: opentelemetryProto.common.v1.StringKeyValue[];
startTimeUnixNano: number;
timeUnixNano: number;
count: number;
sum: number;
buckets?: opentelemetryProto.metrics.v1.HistogramDataPointBucket[];
explicitBounds?: number[];
}

export interface HistogramDataPointBucket {
count: number;
exemplar?: opentelemetryProto.metrics.v1.HistogramExemplar;
}

export interface HistogramExemplar {
value: number;
timeUnixNano: number;
attachments: opentelemetryProto.common.v1.StringKeyValue[];
}

export interface SummaryDataPoint {
labels: opentelemetryProto.common.v1.StringKeyValue[];
startTimeUnixNano: number;
timeUnixNano: number;
count?: number;
sum?: number;
percentileValues: opentelemetryProto.metrics.v1.SummaryDataPointValueAtPercentile[];
}

export interface SummaryDataPointValueAtPercentile {
percentile: number;
value: number;
}

export interface MetricDescriptor {
name: string;
description: string;
unit: string;
type: opentelemetryProto.metrics.v1.MetricDescriptorType;
temporality: opentelemetryProto.metrics.v1.MetricDescriptorTemporality;
}

export interface InstrumentationLibraryMetrics {
instrumentationLibrary?: opentelemetryProto.common.v1.InstrumentationLibrary;
metrics: opentelemetryProto.metrics.v1.Metric[];
}

export interface ResourceMetrics {
resource?: opentelemetryProto.resource.v1.Resource;
instrumentationLibraryMetrics: opentelemetryProto.metrics.v1.InstrumentationLibraryMetrics[];
}

export enum MetricDescriptorType {
INVALID_TYPE,
INT64,
MONOTONIC_INT64,
DOUBLE,
MONOTONIC_DOUBLE,
HISTOGRAM,
SUMMARY,
}

export enum MetricDescriptorTemporality {
INVALID_TEMPORALITY,
INSTANTANEOUS,
DELTA,
CUMULATIVE,
}
}

export namespace trace.v1 {
export namespace ConstantSampler {
export enum ConstantDecision {
Expand Down Expand Up @@ -185,23 +278,6 @@ export interface CollectorExporterConfigBase {
url?: string;
}

/**
* Collector Exporter Config for Web
*/
export interface CollectorExporterConfigBrowser
extends CollectorExporterConfigBase {
headers?: { [key: string]: string };
}

/**
* Collector Exporter Config for Node
*/
export interface CollectorExporterConfigNode
extends CollectorExporterConfigBase {
credentials?: grpc.ChannelCredentials;
metadata?: grpc.Metadata;
}

/**
* Mapping between api SpanKind and proto SpanKind
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import * as assert from 'assert';
import * as sinon from 'sinon';
import { CollectorTraceExporter } from '../../src/platform/browser/index';
import * as collectorTypes from '../../src/types';
import { CollectorExporterConfigBrowser } from '../../src/platform/browser/types';

import {
ensureSpanIsCorrect,
Expand All @@ -32,7 +33,7 @@ const sendBeacon = navigator.sendBeacon;

describe('CollectorTraceExporter - web', () => {
let collectorTraceExporter: CollectorTraceExporter;
let collectorExporterConfig: collectorTypes.CollectorExporterConfigBrowser;
let collectorExporterConfig: CollectorExporterConfigBrowser;
let spyOpen: any;
let spySend: any;
let spyBeacon: any;
Expand Down

0 comments on commit 413edb5

Please sign in to comment.