forked from open-telemetry/opentelemetry-collector-contrib
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[extension/awsmiddleware] Add ID to context to trace requests. (#128)
- Loading branch information
Showing
12 changed files
with
292 additions
and
151 deletions.
There are no files selected for viewing
Validating CODEOWNERS rules …
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,30 @@ | ||
# AWS Middleware | ||
|
||
An AWS middleware extension provides request and/or response handlers that can be configured on AWS SDK v1/v2 clients. | ||
Other components can configure their AWS SDK clients using the `awsmiddleware.ConfigureSDKv1` and `awsmiddleware.ConfigureSDKv2` functions. | ||
Other components can configure their AWS SDK clients using `awsmiddleware.GetConfigurer` and the `ConfigureSDKv1` and | ||
`ConfigureSDKv2` functions available on the `Configurer`. | ||
|
||
The `awsmiddleware.Extension` interface extends `component.Extension` by adding the following methods: | ||
The `awsmiddleware.Extension` interface extends `component.Extension` by adding the following method: | ||
``` | ||
RequestHandlers() []RequestHandler | ||
ResponseHandlers() []ResponseHandler | ||
Handlers() ([]RequestHandler, []ResponseHandler) | ||
``` | ||
|
||
The `awsmiddleware.RequestHandler` interface contains the following methods: | ||
``` | ||
ID() string | ||
Position() HandlerPosition | ||
HandleRequest(r *http.Request) | ||
HandleRequest(id string, r *http.Request) | ||
``` | ||
|
||
The `awsmiddleware.ResponseHandler` interface contains the following methods: | ||
``` | ||
ID() string | ||
Position() HandlerPosition | ||
HandleResponse(r *http.Response) | ||
HandleResponse(id string, r *http.Response) | ||
``` | ||
|
||
- `ID` uniquely identifies a handler. Middleware will fail if there is clashing | ||
- `Position` determines whether the handler is appended to the front or back of the existing list. Insertion is done | ||
in the order of the handlers provided. | ||
- `HandleRequest/Response` provides a hook to handle the request/response before and after they've been sent. | ||
- `HandleRequest/Response` provides a hook to handle the request/response before and after they've been sent along | ||
with an attached request ID. |
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 |
---|---|---|
@@ -1,27 +1,33 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package awsmiddleware // import "github.com/open-telemetry/opentelemetry-collector-contrib/extension/awsmiddleware" | ||
package awsmiddleware // import "github.com/amazon-contributing/opentelemetry-collector-contrib/extension/awsmiddleware" | ||
|
||
import ( | ||
"fmt" | ||
|
||
"go.opentelemetry.io/collector/component" | ||
) | ||
|
||
// Config defines the configuration for an AWS Middleware extension. | ||
type Config struct { | ||
// MiddlewareID is the ID of the Middleware extension. | ||
MiddlewareID component.ID `mapstructure:"middleware"` | ||
} | ||
type ID = component.ID | ||
|
||
// GetMiddleware retrieves the extension implementing Middleware based on the MiddlewareID. | ||
func (c Config) GetMiddleware(extensions map[component.ID]component.Component) (Middleware, error) { | ||
if ext, found := extensions[c.MiddlewareID]; found { | ||
if mw, ok := ext.(Middleware); ok { | ||
return mw, nil | ||
// getMiddleware retrieves the extension implementing Middleware based on the middlewareID. | ||
func getMiddleware(extensions map[component.ID]component.Component, middlewareID ID) (Middleware, error) { | ||
if extension, found := extensions[middlewareID]; found { | ||
if middleware, ok := extension.(Middleware); ok { | ||
return middleware, nil | ||
} | ||
return nil, errNotMiddleware | ||
} | ||
return nil, fmt.Errorf("failed to resolve AWS client handler %q: %w", c.MiddlewareID, errNotFound) | ||
return nil, fmt.Errorf("failed to resolve AWS middleware %q: %w", middlewareID, errNotFound) | ||
} | ||
|
||
// GetConfigurer retrieves the extension implementing Middleware based on the middlewareID and | ||
// wraps it in a Configurer. | ||
func GetConfigurer(extensions map[component.ID]component.Component, middlewareID ID) (*Configurer, error) { | ||
middleware, err := getMiddleware(extensions, middlewareID) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return newConfigurer(middleware.Handlers()), nil | ||
} |
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.