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

refactor: normalize namespace import name for @opentelemetry/api #1016

Merged
merged 1 commit into from
May 5, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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
24 changes: 12 additions & 12 deletions packages/opentelemetry-core/src/common/time.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import * as types from '@opentelemetry/api';
import * as api from '@opentelemetry/api';
import { otperformance as performance } from '../platform';
import { TimeOriginLegacy } from './types';

Expand All @@ -25,7 +25,7 @@ const SECOND_TO_NANOSECONDS = Math.pow(10, NANOSECOND_DIGITS);
* Converts a number to HrTime
* @param epochMillis
*/
function numberToHrtime(epochMillis: number): types.HrTime {
function numberToHrtime(epochMillis: number): api.HrTime {
const epochSeconds = epochMillis / 1000;
// Decimals only.
const seconds = Math.trunc(epochSeconds);
Expand All @@ -49,7 +49,7 @@ function getTimeOrigin(): number {
* Returns an hrtime calculated via performance component.
* @param performanceNow
*/
export function hrTime(performanceNow?: number): types.HrTime {
export function hrTime(performanceNow?: number): api.HrTime {
const timeOrigin = numberToHrtime(getTimeOrigin());
const now = numberToHrtime(
typeof performanceNow === 'number' ? performanceNow : performance.now()
Expand All @@ -72,10 +72,10 @@ export function hrTime(performanceNow?: number): types.HrTime {
* Converts a TimeInput to an HrTime, defaults to _hrtime().
* @param time
*/
export function timeInputToHrTime(time: types.TimeInput): types.HrTime {
export function timeInputToHrTime(time: api.TimeInput): api.HrTime {
// process.hrtime
if (isTimeInputHrTime(time)) {
return time as types.HrTime;
return time as api.HrTime;
} else if (typeof time === 'number') {
// Must be a performance.now() if it's smaller than process start time.
if (time < getTimeOrigin()) {
Expand All @@ -97,9 +97,9 @@ export function timeInputToHrTime(time: types.TimeInput): types.HrTime {
* @param endTime
*/
export function hrTimeDuration(
startTime: types.HrTime,
endTime: types.HrTime
): types.HrTime {
startTime: api.HrTime,
endTime: api.HrTime
): api.HrTime {
let seconds = endTime[0] - startTime[0];
let nanos = endTime[1] - startTime[1];

Expand All @@ -117,7 +117,7 @@ export function hrTimeDuration(
* Convert hrTime to timestamp, for example "2019-05-14T17:00:00.000123456Z"
* @param hrTime
*/
export function hrTimeToTimeStamp(hrTime: types.HrTime): string {
export function hrTimeToTimeStamp(hrTime: api.HrTime): string {
const precision = NANOSECOND_DIGITS;
const tmp = `${'0'.repeat(precision)}${hrTime[1]}Z`;
const nanoString = tmp.substr(tmp.length - precision - 1);
Expand All @@ -129,23 +129,23 @@ export function hrTimeToTimeStamp(hrTime: types.HrTime): string {
* Convert hrTime to nanoseconds.
* @param hrTime
*/
export function hrTimeToNanoseconds(hrTime: types.HrTime): number {
export function hrTimeToNanoseconds(hrTime: api.HrTime): number {
return hrTime[0] * SECOND_TO_NANOSECONDS + hrTime[1];
}

/**
* Convert hrTime to milliseconds.
* @param hrTime
*/
export function hrTimeToMilliseconds(hrTime: types.HrTime): number {
export function hrTimeToMilliseconds(hrTime: api.HrTime): number {
return Math.round(hrTime[0] * 1e3 + hrTime[1] / 1e6);
}

/**
* Convert hrTime to microseconds.
* @param hrTime
*/
export function hrTimeToMicroseconds(hrTime: types.HrTime): number {
export function hrTimeToMicroseconds(hrTime: api.HrTime): number {
return Math.round(hrTime[0] * 1e6 + hrTime[1] / 1e3);
}

Expand Down
4 changes: 2 additions & 2 deletions packages/opentelemetry-core/src/trace/TraceState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import * as types from '@opentelemetry/api';
import * as api from '@opentelemetry/api';
import { validateKey, validateValue } from '../internal/validators';

const MAX_TRACE_STATE_ITEMS = 32;
Expand All @@ -31,7 +31,7 @@ const LIST_MEMBER_KEY_VALUE_SPLITTER = '=';
* - The value of any key can be updated. Modified keys MUST be moved to the
* beginning of the list.
*/
export class TraceState implements types.TraceState {
export class TraceState implements api.TraceState {
private _internalState: Map<string, string> = new Map();

constructor(rawTraceState?: string) {
Expand Down
12 changes: 6 additions & 6 deletions packages/opentelemetry-core/test/common/time.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import * as assert from 'assert';
import { otperformance as performance } from '../../src/platform';
import * as sinon from 'sinon';
import * as types from '@opentelemetry/api';
import * as api from '@opentelemetry/api';
import {
hrTime,
timeInputToHrTime,
Expand Down Expand Up @@ -141,16 +141,16 @@ describe('time', () => {

describe('#hrTimeDuration', () => {
it('should return duration', () => {
const startTime: types.HrTime = [22, 400000000];
const endTime: types.HrTime = [32, 800000000];
const startTime: api.HrTime = [22, 400000000];
const endTime: api.HrTime = [32, 800000000];

const output = hrTimeDuration(startTime, endTime);
assert.deepStrictEqual(output, [10, 400000000]);
});

it('should handle nanosecond overflow', () => {
const startTime: types.HrTime = [22, 400000000];
const endTime: types.HrTime = [32, 200000000];
const startTime: api.HrTime = [22, 400000000];
const endTime: api.HrTime = [32, 200000000];

const output = hrTimeDuration(startTime, endTime);
assert.deepStrictEqual(output, [9, 800000000]);
Expand All @@ -159,7 +159,7 @@ describe('time', () => {

describe('#hrTimeToTimeStamp', () => {
it('should return timestamp', () => {
const time: types.HrTime = [1573513121, 123456];
const time: api.HrTime = [1573513121, 123456];

const output = hrTimeToTimeStamp(time);
assert.deepStrictEqual(output, '2019-11-11T22:58:41.000123456Z');
Expand Down
4 changes: 2 additions & 2 deletions packages/opentelemetry-exporter-jaeger/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
* limitations under the License.
*/

import * as types from '@opentelemetry/api';
import * as api from '@opentelemetry/api';

/**
* Options for Jaeger configuration
*/
export interface ExporterConfig {
logger?: types.Logger;
logger?: api.Logger;
serviceName: string;
tags?: Tag[];
host?: string; // default: 'localhost'
Expand Down
6 changes: 3 additions & 3 deletions packages/opentelemetry-exporter-jaeger/test/jaeger.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import * as assert from 'assert';
import { JaegerExporter } from '../src';
import { ExportResult, NoopLogger } from '@opentelemetry/core';
import * as types from '@opentelemetry/api';
import * as api from '@opentelemetry/api';
import { ThriftProcess } from '../src/types';
import { ReadableSpan } from '@opentelemetry/tracing';
import { TraceFlags } from '@opentelemetry/api';
Expand Down Expand Up @@ -130,13 +130,13 @@ describe('JaegerExporter', () => {
};
const readableSpan: ReadableSpan = {
name: 'my-span1',
kind: types.SpanKind.CLIENT,
kind: api.SpanKind.CLIENT,
spanContext,
startTime: [1566156729, 709],
endTime: [1566156731, 709],
ended: true,
status: {
code: types.CanonicalCode.DATA_LOSS,
code: api.CanonicalCode.DATA_LOSS,
},
attributes: {},
links: [],
Expand Down
18 changes: 9 additions & 9 deletions packages/opentelemetry-exporter-jaeger/test/transform.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import * as assert from 'assert';
import { spanToThrift } from '../src/transform';
import { ReadableSpan } from '@opentelemetry/tracing';
import { Resource } from '@opentelemetry/resources';
import * as types from '@opentelemetry/api';
import * as api from '@opentelemetry/api';
import { ThriftUtils, Utils, ThriftReferenceType } from '../src/types';
import { hrTimeToMicroseconds } from '@opentelemetry/core';
import { TraceFlags } from '@opentelemetry/api';
Expand All @@ -34,13 +34,13 @@ describe('transform', () => {
it('should convert an OpenTelemetry span to a Thrift', () => {
const readableSpan: ReadableSpan = {
name: 'my-span',
kind: types.SpanKind.INTERNAL,
kind: api.SpanKind.INTERNAL,
spanContext,
startTime: [1566156729, 709],
endTime: [1566156731, 709],
ended: true,
status: {
code: types.CanonicalCode.OK,
code: api.CanonicalCode.OK,
},
attributes: {
testBool: true,
Expand Down Expand Up @@ -155,13 +155,13 @@ describe('transform', () => {
it('should convert an OpenTelemetry span to a Thrift when links, events and attributes are empty', () => {
const readableSpan: ReadableSpan = {
name: 'my-span1',
kind: types.SpanKind.CLIENT,
kind: api.SpanKind.CLIENT,
spanContext,
startTime: [1566156729, 709],
endTime: [1566156731, 709],
ended: true,
status: {
code: types.CanonicalCode.DATA_LOSS,
code: api.CanonicalCode.DATA_LOSS,
message: 'data loss',
},
attributes: {},
Expand Down Expand Up @@ -213,13 +213,13 @@ describe('transform', () => {
it('should convert an OpenTelemetry span to a Thrift with ThriftReference', () => {
const readableSpan: ReadableSpan = {
name: 'my-span',
kind: types.SpanKind.INTERNAL,
kind: api.SpanKind.INTERNAL,
spanContext,
startTime: [1566156729, 709],
endTime: [1566156731, 709],
ended: true,
status: {
code: types.CanonicalCode.OK,
code: api.CanonicalCode.OK,
},
attributes: {},
parentSpanId: '3e0c63257de34c92',
Expand Down Expand Up @@ -255,7 +255,7 @@ describe('transform', () => {
it('should left pad trace ids', () => {
const readableSpan: ReadableSpan = {
name: 'my-span1',
kind: types.SpanKind.CLIENT,
kind: api.SpanKind.CLIENT,
spanContext: {
traceId: '92b449d5929fda1b',
spanId: '6e0c63257de34c92',
Expand All @@ -265,7 +265,7 @@ describe('transform', () => {
endTime: [1566156731, 709],
ended: true,
status: {
code: types.CanonicalCode.DATA_LOSS,
code: api.CanonicalCode.DATA_LOSS,
message: 'data loss',
},
attributes: {},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import * as types from '@opentelemetry/api';
import * as api from '@opentelemetry/api';

/**
* Configuration interface for prometheus exporter
Expand Down Expand Up @@ -49,5 +49,5 @@ export interface ExporterConfig {
startServer?: boolean;

/** Standard logging interface */
logger?: types.Logger;
logger?: api.Logger;
}
6 changes: 3 additions & 3 deletions packages/opentelemetry-exporter-prometheus/src/prometheus.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import {
ObserverAggregator,
Sum,
} from '@opentelemetry/metrics';
import * as types from '@opentelemetry/api';
import * as api from '@opentelemetry/api';
import { createServer, IncomingMessage, Server, ServerResponse } from 'http';
import { Counter, Gauge, labelValues, Metric, Registry } from 'prom-client';
import * as url from 'url';
Expand All @@ -44,7 +44,7 @@ export class PrometheusExporter implements MetricExporter {
};

private readonly _registry = new Registry();
private readonly _logger: types.Logger;
private readonly _logger: api.Logger;
private readonly _port: number;
private readonly _endpoint: string;
private readonly _server: Server;
Expand Down Expand Up @@ -159,7 +159,7 @@ export class PrometheusExporter implements MetricExporter {
// TODO: only counter and gauge are implemented in metrics so far
}

private _getLabelValues(keys: string[], labels: types.Labels) {
private _getLabelValues(keys: string[], labels: api.Labels) {
const labelValues: labelValues = {};
for (let i = 0; i < keys.length; i++) {
if (labels[keys[i]] !== null) {
Expand Down
20 changes: 10 additions & 10 deletions packages/opentelemetry-exporter-zipkin/src/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@
* limitations under the License.
*/

import * as types from '@opentelemetry/api';
import * as api from '@opentelemetry/api';
import { ReadableSpan } from '@opentelemetry/tracing';
import { hrTimeToMicroseconds } from '@opentelemetry/core';
import * as zipkinTypes from './types';
import { Resource } from '@opentelemetry/resources';

const ZIPKIN_SPAN_KIND_MAPPING = {
[types.SpanKind.CLIENT]: zipkinTypes.SpanKind.CLIENT,
[types.SpanKind.SERVER]: zipkinTypes.SpanKind.SERVER,
[types.SpanKind.CONSUMER]: zipkinTypes.SpanKind.CONSUMER,
[types.SpanKind.PRODUCER]: zipkinTypes.SpanKind.PRODUCER,
[api.SpanKind.CLIENT]: zipkinTypes.SpanKind.CLIENT,
[api.SpanKind.SERVER]: zipkinTypes.SpanKind.SERVER,
[api.SpanKind.CONSUMER]: zipkinTypes.SpanKind.CONSUMER,
[api.SpanKind.PRODUCER]: zipkinTypes.SpanKind.PRODUCER,
// When absent, the span is local.
[types.SpanKind.INTERNAL]: undefined,
[api.SpanKind.INTERNAL]: undefined,
};

export const statusCodeTagName = 'ot.status_code';
Expand Down Expand Up @@ -68,8 +68,8 @@ export function toZipkinSpan(

/** Converts OpenTelemetry Attributes and Status to Zipkin Tags format. */
export function _toZipkinTags(
attributes: types.Attributes,
status: types.Status,
attributes: api.Attributes,
status: api.Status,
statusCodeTagName: string,
statusDescriptionTagName: string,
resource: Resource
Expand All @@ -78,7 +78,7 @@ export function _toZipkinTags(
for (const key of Object.keys(attributes)) {
tags[key] = String(attributes[key]);
}
tags[statusCodeTagName] = String(types.CanonicalCode[status.code]);
tags[statusCodeTagName] = String(api.CanonicalCode[status.code]);
if (status.message) {
tags[statusDescriptionTagName] = status.message;
}
Expand All @@ -94,7 +94,7 @@ export function _toZipkinTags(
* Converts OpenTelemetry Events to Zipkin Annotations format.
*/
export function _toZipkinAnnotations(
events: types.TimedEvent[]
events: api.TimedEvent[]
): zipkinTypes.Annotation[] {
return events.map(event => ({
timestamp: hrTimeToMicroseconds(event.time),
Expand Down
4 changes: 2 additions & 2 deletions packages/opentelemetry-exporter-zipkin/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@
* limitations under the License.
*/

import * as types from '@opentelemetry/api';
import * as api from '@opentelemetry/api';

/**
* Exporter config
*/
export interface ExporterConfig {
logger?: types.Logger;
logger?: api.Logger;
serviceName: string;
url?: string;
// Optional mapping overrides for OpenTelemetry status code and description.
Expand Down
4 changes: 2 additions & 2 deletions packages/opentelemetry-exporter-zipkin/src/zipkin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

import * as types from '@opentelemetry/api';
import * as api from '@opentelemetry/api';
import * as http from 'http';
import * as https from 'https';
import * as url from 'url';
Expand All @@ -32,7 +32,7 @@ import { OT_REQUEST_HEADER } from './utils';
*/
export class ZipkinExporter implements SpanExporter {
static readonly DEFAULT_URL = 'http://localhost:9411/api/v2/spans';
private readonly _logger: types.Logger;
private readonly _logger: api.Logger;
private readonly _serviceName: string;
private readonly _statusCodeTagName: string;
private readonly _statusDescriptionTagName: string;
Expand Down
Loading