generated from amazon-archives/__template_Apache-2.0
-
Notifications
You must be signed in to change notification settings - Fork 15
SigV4 Authentication Support for OTLP HTTP Logs Exporter #181
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
6d12166
initial commit
liustve 6b3ceb1
sigv4 authentication support for otlp logs exporter
liustve 511de17
Merge branch 'main' into sigv4_logs
liustve c577ac8
Merge branch 'main' into sigv4_logs
liustve 8f753e3
add preprocessing for compression
liustve 6796342
consolidate logs and span exporters
liustve cee3bf2
cleanup base exporter
liustve 77ebe43
Merge branch 'main' into sigv4_logs
liustve cf40551
refactor more changes to base exporter
liustve 06fc811
Merge branch 'sigv4_logs' of https://github.com/liustve/aws-otel-js-i…
liustve 5b69509
add better log messages
liustve 7dbfbe3
Merge branch 'main' into sigv4_logs
liustve fc374b2
add logs processor test
liustve bb280d4
Merge branch 'sigv4_logs' of https://github.com/liustve/aws-otel-js-i…
liustve aa2fab1
Merge remote-tracking branch 'upstream/main' into sigv4_logs
liustve 54f3229
remove duplicate llo handlers
liustve 2564edd
add export failed return to aws span exporter
liustve e36a136
fixed stubbing method
liustve 2408204
add unit tests
liustve 39abd64
add comment for prevalidated URL
liustve e3ac125
Merge remote-tracking branch 'upstream/main' into sigv4_logs
liustve 76b1d72
move done
liustve File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
100 changes: 100 additions & 0 deletions
100
...telemetry-node-autoinstrumentation/src/exporter/otlp/aws/common/otlp-aws-base-exporter.ts
This file contains hidden or 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,100 @@ | ||
| // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| import { CompressionAlgorithm, OTLPExporterBase } from '@opentelemetry/otlp-exporter-base'; | ||
| import { gzipSync } from 'zlib'; | ||
| import { ExportResult, ExportResultCode } from '@opentelemetry/core'; | ||
| import { AwsAuthenticator } from './aws-authenticator'; | ||
| import { PassthroughSerializer } from './passthrough-serializer'; | ||
| import { ISerializer } from '@opentelemetry/otlp-transformer'; | ||
|
|
||
| /** | ||
| * Base class for AWS OTLP exporters | ||
| */ | ||
| export abstract class OTLPAwsBaseExporter<Payload, Response> { | ||
jj22ee marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| protected parentExporter: OTLPExporterBase<Payload>; | ||
| private compression?: CompressionAlgorithm; | ||
| private endpoint: string; | ||
| private serializer: PassthroughSerializer<Response>; | ||
| private authenticator: AwsAuthenticator; | ||
| private parentSerializer: ISerializer<Payload, Response>; | ||
|
|
||
| constructor( | ||
| endpoint: string, | ||
| service: string, | ||
| parentExporter: OTLPExporterBase<Payload>, | ||
| parentSerializer: ISerializer<Payload, Response>, | ||
| compression?: CompressionAlgorithm | ||
| ) { | ||
| this.compression = compression; | ||
| this.endpoint = endpoint; | ||
| this.authenticator = new AwsAuthenticator(this.endpoint, service); | ||
| this.parentExporter = parentExporter; | ||
| this.parentSerializer = parentSerializer; | ||
|
|
||
| // To prevent performance degradation from serializing and compressing data twice, we handle serialization and compression | ||
| // locally in this exporter and pass the pre-processed data to the upstream export. | ||
| // This is used in order to prevent serializing and compressing the data again when calling parentExporter.export(). | ||
| // To see why this works: | ||
| // https://github.com/open-telemetry/opentelemetry-js/blob/ec17ce48d0e5a99a122da5add612a20e2dd84ed5/experimental/packages/otlp-exporter-base/src/otlp-export-delegate.ts#L69 | ||
| this.serializer = new PassthroughSerializer<Response>(this.parentSerializer.deserializeResponse); | ||
|
|
||
| this.parentExporter['_delegate']._serializer = this.serializer; | ||
| } | ||
|
|
||
| /** | ||
| * Overrides the upstream implementation of export. | ||
| * All behaviors are the same except if the endpoint is an AWS OTLP endpoint, we will sign the request with SigV4 | ||
| * in headers before sending it to the endpoint. | ||
| * @param items - Array of signal data to export | ||
| * @param resultCallback - Callback function to handle export result | ||
| */ | ||
| public async export(items: Payload, resultCallback: (result: ExportResult) => void): Promise<void> { | ||
| let serializedData: Uint8Array | undefined = this.parentSerializer.serializeRequest(items); | ||
|
|
||
| if (!serializedData) { | ||
| resultCallback({ | ||
| code: ExportResultCode.FAILED, | ||
| error: new Error('Nothing to send'), | ||
| }); | ||
| return; | ||
| } | ||
|
|
||
| const headers = this.parentExporter['_delegate']._transport?._transport?._parameters?.headers(); | ||
|
|
||
| // This should never be reached as upstream always sets the header. | ||
| if (!headers) { | ||
| resultCallback({ | ||
| code: ExportResultCode.FAILED, | ||
| error: new Error(`Request headers are undefined - unable to export to ${this.endpoint}`), | ||
| }); | ||
|
|
||
| return; | ||
| } | ||
|
|
||
| delete headers['Content-Encoding']; | ||
jj22ee marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| const shouldCompress = this.compression && this.compression !== CompressionAlgorithm.NONE; | ||
|
|
||
| if (shouldCompress) { | ||
| try { | ||
| serializedData = gzipSync(serializedData); | ||
| headers['Content-Encoding'] = 'gzip'; | ||
| } catch (exception) { | ||
| resultCallback({ | ||
| code: ExportResultCode.FAILED, | ||
| error: new Error(`Failed to compress: ${exception}`), | ||
| }); | ||
| return; | ||
| } | ||
| } | ||
|
|
||
| this.serializer.setSerializedData(serializedData); | ||
|
|
||
| const signedRequestHeaders = await this.authenticator.authenticate(headers, serializedData); | ||
|
|
||
| if (signedRequestHeaders) { | ||
| this.parentExporter['_delegate']._transport._transport._parameters.headers = () => signedRequestHeaders; | ||
| } | ||
|
|
||
| this.parentExporter.export(items, resultCallback); | ||
| } | ||
| } | ||
15 changes: 0 additions & 15 deletions
15
aws-distro-opentelemetry-node-autoinstrumentation/src/exporter/otlp/aws/common/utils.ts
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.