-
Notifications
You must be signed in to change notification settings - Fork 813
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(otlp-grpc-exporter-base): use statically generated protobuf code (…
…#3705) Co-authored-by: Daniel Dyla <dyladan@users.noreply.github.com>
- Loading branch information
1 parent
abfb1bb
commit 2f1e316
Showing
14 changed files
with
246 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
src/generated/* | ||
!src/generated/.gitkeep |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
experimental/packages/otlp-grpc-exporter-base/src/LogsExportServiceClient.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* 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 * as grpc from '@grpc/grpc-js'; | ||
import { IExportLogsServiceRequest } from '@opentelemetry/otlp-transformer'; | ||
import { ExportType } from './internal-types'; | ||
import IExportLogsServiceResponse = root.opentelemetry.proto.collector.logs.v1.IExportLogsServiceResponse; | ||
|
||
const responseType = root.opentelemetry.proto.collector.logs.v1 | ||
.ExportLogsServiceResponse as ExportType<IExportLogsServiceResponse>; | ||
|
||
const requestType = root.opentelemetry.proto.collector.logs.v1 | ||
.ExportLogsServiceRequest as ExportType<IExportLogsServiceRequest>; | ||
|
||
const logsServiceDefinition = { | ||
export: { | ||
path: '/opentelemetry.proto.collector.logs.v1.LogsService/Export', | ||
requestStream: false, | ||
responseStream: false, | ||
requestSerialize: (arg: IExportLogsServiceRequest) => { | ||
return Buffer.from(requestType.encode(arg).finish()); | ||
}, | ||
requestDeserialize: (arg: Buffer) => { | ||
return requestType.decode(arg); | ||
}, | ||
responseSerialize: (arg: IExportLogsServiceResponse) => { | ||
return Buffer.from(responseType.encode(arg).finish()); | ||
}, | ||
responseDeserialize: (arg: Buffer) => { | ||
return responseType.decode(arg); | ||
}, | ||
}, | ||
}; | ||
|
||
// Creates a new instance of a gRPC service client for OTLP logs | ||
export const LogsExportServiceClient: grpc.ServiceClientConstructor = | ||
grpc.makeGenericClientConstructor(logsServiceDefinition, 'LogsExportService'); |
54 changes: 54 additions & 0 deletions
54
experimental/packages/otlp-grpc-exporter-base/src/MetricsExportServiceClient.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* 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 * as grpc from '@grpc/grpc-js'; | ||
import { IExportMetricsServiceRequest } from '@opentelemetry/otlp-transformer'; | ||
import { ExportType } from './internal-types'; | ||
import IExportMetricsServiceResponse = root.opentelemetry.proto.collector.metrics.v1.IExportMetricsServiceResponse; | ||
|
||
const responseType = root.opentelemetry.proto.collector.metrics.v1 | ||
.ExportMetricsServiceResponse as ExportType<IExportMetricsServiceResponse>; | ||
|
||
const requestType = root.opentelemetry.proto.collector.metrics.v1 | ||
.ExportMetricsServiceRequest as ExportType<IExportMetricsServiceRequest>; | ||
|
||
const metricsServiceDefinition = { | ||
export: { | ||
path: '/opentelemetry.proto.collector.metrics.v1.MetricsService/Export', | ||
requestStream: false, | ||
responseStream: false, | ||
requestSerialize: (arg: IExportMetricsServiceRequest) => { | ||
return Buffer.from(requestType.encode(arg).finish()); | ||
}, | ||
requestDeserialize: (arg: Buffer) => { | ||
return requestType.decode(arg); | ||
}, | ||
responseSerialize: (arg: IExportMetricsServiceResponse) => { | ||
return Buffer.from(responseType.encode(arg).finish()); | ||
}, | ||
responseDeserialize: (arg: Buffer) => { | ||
return responseType.decode(arg); | ||
}, | ||
}, | ||
}; | ||
|
||
// Creates a new instance of a gRPC service client for OTLP metrics | ||
export const MetricExportServiceClient: grpc.ServiceClientConstructor = | ||
grpc.makeGenericClientConstructor( | ||
metricsServiceDefinition, | ||
'MetricsExportService' | ||
); |
54 changes: 54 additions & 0 deletions
54
experimental/packages/otlp-grpc-exporter-base/src/TraceExportServiceClient.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* 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 * as grpc from '@grpc/grpc-js'; | ||
import { IExportTraceServiceRequest } from '@opentelemetry/otlp-transformer'; | ||
import { ExportType } from './internal-types'; | ||
import IExportTraceServiceResponse = root.opentelemetry.proto.collector.trace.v1.IExportTraceServiceResponse; | ||
|
||
const responseType = root.opentelemetry.proto.collector.trace.v1 | ||
.ExportTraceServiceResponse as ExportType<IExportTraceServiceResponse>; | ||
|
||
const requestType = root.opentelemetry.proto.collector.trace.v1 | ||
.ExportTraceServiceRequest as ExportType<IExportTraceServiceRequest>; | ||
|
||
const traceServiceDefinition = { | ||
export: { | ||
path: '/opentelemetry.proto.collector.trace.v1.TraceService/Export', | ||
requestStream: false, | ||
responseStream: false, | ||
requestSerialize: (arg: IExportTraceServiceRequest) => { | ||
return Buffer.from(requestType.encode(arg).finish()); | ||
}, | ||
requestDeserialize: (arg: Buffer) => { | ||
return requestType.decode(arg); | ||
}, | ||
responseSerialize: (arg: IExportTraceServiceResponse) => { | ||
return Buffer.from(responseType.encode(arg).finish()); | ||
}, | ||
responseDeserialize: (arg: Buffer) => { | ||
return responseType.decode(arg); | ||
}, | ||
}, | ||
}; | ||
|
||
// Creates a new instance of a gRPC service client for exporting OTLP traces | ||
export const TraceExportServiceClient: grpc.ServiceClientConstructor = | ||
grpc.makeGenericClientConstructor( | ||
traceServiceDefinition, | ||
'TraceExportService' | ||
); |
Empty file.
22 changes: 22 additions & 0 deletions
22
experimental/packages/otlp-grpc-exporter-base/src/internal-types.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* 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 type * as protobuf from 'protobufjs'; | ||
|
||
export interface ExportType<T, R = T & { toJSON: () => unknown }> { | ||
encode(message: T, writer?: protobuf.Writer): protobuf.Writer; | ||
decode(reader: protobuf.Reader | Uint8Array, length?: number): R; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.