Skip to content

Commit

Permalink
fix:suggested changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Abinet18 committed May 9, 2023
1 parent c8d6a36 commit 3911bd0
Show file tree
Hide file tree
Showing 8 changed files with 49 additions and 36 deletions.
3 changes: 1 addition & 2 deletions experimental/packages/exporter-logs-otlp-proto/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# OpenTelemetry Collector Exporter for node with protobuf
# An OTLP exporter to send logs using protobuf over HTTP

[![NPM Published Version][npm-img]][npm-url]
[![Apache License][license-image]][license-image]
Expand Down Expand Up @@ -42,7 +42,6 @@ const logger = logProvider.getLogger('test_log_instrumentation');
logger.emit({
//log data to emit
})

```

## Exporter Timeout Configuration
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@opentelemetry/exporter-logs-otlp-proto",
"version": "0.38.0",
"description": "OpenTelemetry Collector Exporter allows user to send collected logs to the OpenTelemetry Collector using json over Protobuf",
"description": "An OTLP exporter to send logs using protobuf over HTTP",
"main": "build/src/index.js",
"module": "build/esm/index.js",
"esnext": "build/esnext/index.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import {
sendWithXhr,
} from '@opentelemetry/otlp-exporter-base';

import { getExportRequestProto } from '../node';
import { getExportRequestProto } from '../util';

interface ExportRequestType<T, R = T & { toJSON: () => unknown }> {
create(properties?: T): R;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,7 @@
* limitations under the License.
*/

export {
OTLPProtoExporterNodeBase,
ExportRequestType,
getExportRequestProto,
send,
} from './node';
export { OTLPProtoExporterNodeBase, send } from './node';
export { OTLPProtoExporterBrowserBase } from './browser';
export { ServiceClientType } from './types';
export { ExportRequestType, getExportRequestProto } from './util';
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@
*/

export { OTLPProtoExporterNodeBase } from './OTLPProtoExporterNodeBase';
export { ExportRequestType, getExportRequestProto, send } from './util';
export { send } from './util';
Original file line number Diff line number Diff line change
Expand Up @@ -14,36 +14,14 @@
* limitations under the License.
*/

import { ServiceClientType } from '../types';
import { OTLPProtoExporterNodeBase } from './OTLPProtoExporterNodeBase';
import {
CompressionAlgorithm,
OTLPExporterError,
sendWithHttp,
} from '@opentelemetry/otlp-exporter-base';
import type * as protobuf from 'protobufjs';
import * as root from '../../generated/root';

export interface ExportRequestType<T, R = T & { toJSON: () => unknown }> {
create(properties?: T): R;
encode(message: T, writer?: protobuf.Writer): protobuf.Writer;
decode(reader: protobuf.Reader | Uint8Array, length?: number): R;
}

export function getExportRequestProto<ServiceRequest>(
clientType: ServiceClientType
): ExportRequestType<ServiceRequest> {
if (clientType === ServiceClientType.SPANS) {
return root.opentelemetry.proto.collector.trace.v1
.ExportTraceServiceRequest as unknown as ExportRequestType<ServiceRequest>;
} else if (clientType === ServiceClientType.LOGS) {
return root.opentelemetry.proto.collector.logs.v1
.ExportLogsServiceRequest as unknown as ExportRequestType<ServiceRequest>;
} else {
return root.opentelemetry.proto.collector.metrics.v1
.ExportMetricsServiceRequest as unknown as ExportRequestType<ServiceRequest>;
}
}
import { getExportRequestProto } from '../util';

export function send<ExportItem, ServiceRequest>(
collector: OTLPProtoExporterNodeBase<ExportItem, ServiceRequest>,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* 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 * as root from '../generated/root';
import { ServiceClientType } from './types';

export interface ExportRequestType<T, R = T & { toJSON: () => unknown }> {
create(properties?: T): R;
encode(message: T, writer?: protobuf.Writer): protobuf.Writer;
decode(reader: protobuf.Reader | Uint8Array, length?: number): R;
}

export function getExportRequestProto<ServiceRequest>(
clientType: ServiceClientType
): ExportRequestType<ServiceRequest> {
if (clientType === ServiceClientType.SPANS) {
return root.opentelemetry.proto.collector.trace.v1
.ExportTraceServiceRequest as unknown as ExportRequestType<ServiceRequest>;
} else if (clientType === ServiceClientType.LOGS) {
return root.opentelemetry.proto.collector.logs.v1
.ExportLogsServiceRequest as unknown as ExportRequestType<ServiceRequest>;
} else {
return root.opentelemetry.proto.collector.metrics.v1
.ExportMetricsServiceRequest as unknown as ExportRequestType<ServiceRequest>;
}
}
5 changes: 3 additions & 2 deletions experimental/packages/sdk-logs/test/common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@ export const validAttributes = {
'array<string>': ['str1', 'str2'],
'array<number>': [1, 2],
'array<bool>': [true, false],
object: { bar: 'foo' },
};

export const invalidAttributes = {
// invalid attribute type object
// object: { foo: 'bar' },
// invalid attribute empty object
object: {},
// invalid attribute inhomogeneous array
'non-homogeneous-array': [0, ''],
// This empty length attribute should not be set
Expand Down

0 comments on commit 3911bd0

Please sign in to comment.