forked from open-telemetry/opentelemetry-collector-contrib
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[extension/encodingextension] Introduce zipkin encoding extension. (o…
…pen-telemetry#27877) Introduce zipkin encoding extension. For more context, see open-telemetry#27564
- Loading branch information
Showing
17 changed files
with
424 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Use this changelog template to create an entry for release notes. | ||
|
||
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix' | ||
change_type: new_component | ||
|
||
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver) | ||
component: zipkinencodingextension | ||
|
||
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`). | ||
note: Introduce zipkin encoding extension. | ||
|
||
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists. | ||
issues: [6272] | ||
|
||
# (Optional) One or more lines of additional information to render under the primary note. | ||
# These lines will be padded with 2 spaces and then inserted directly into the document. | ||
# Use pipe (|) for multiline entries. | ||
subtext: | ||
|
||
# If your change doesn't affect end users or the exported elements of any package, | ||
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label. | ||
# Optional: The change log or logs in which this entry should be included. | ||
# e.g. '[user]' or '[user, api]' | ||
# Include 'user' if the change is relevant to end users. | ||
# Include 'api' if there is a change to a library API. | ||
# Default: '[user]' | ||
change_logs: [] |
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
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 |
---|---|---|
@@ -0,0 +1 @@ | ||
include ../../../Makefile.Common |
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,12 @@ | ||
# Zipkin encoding extension | ||
|
||
<!-- status autogenerated section --> | ||
| Status | | | ||
| ------------- |-----------| | ||
| Stability | [development] | | ||
| Distributions | [] | | ||
| Issues | [![Open issues](https://img.shields.io/github/issues-search/open-telemetry/opentelemetry-collector-contrib?query=is%3Aissue%20is%3Aopen%20label%3Aextension%2Fzipkinencoding%20&label=open&color=orange&logo=opentelemetry)](https://github.com/open-telemetry/opentelemetry-collector-contrib/issues?q=is%3Aopen+is%3Aissue+label%3Aextension%2Fzipkinencoding) [![Closed issues](https://img.shields.io/github/issues-search/open-telemetry/opentelemetry-collector-contrib?query=is%3Aissue%20is%3Aclosed%20label%3Aextension%2Fzipkinencoding%20&label=closed&color=blue&logo=opentelemetry)](https://github.com/open-telemetry/opentelemetry-collector-contrib/issues?q=is%3Aclosed+is%3Aissue+label%3Aextension%2Fzipkinencoding) | | ||
| [Code Owners](https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/CONTRIBUTING.md#becoming-a-code-owner) | [@MovieStoreGuy](https://www.github.com/MovieStoreGuy), [@dao-jun](https://www.github.com/dao-jun) | | ||
|
||
[development]: https://github.com/open-telemetry/opentelemetry-collector#development | ||
<!-- end autogenerated section --> |
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,27 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package zipkinencodingextension // import "github.com/open-telemetry/opentelemetry-collector-contrib/extension/encoding/zipkinencodingextension" | ||
import ( | ||
"fmt" | ||
|
||
"go.opentelemetry.io/collector/component" | ||
) | ||
|
||
var _ component.ConfigValidator = (*Config)(nil) | ||
|
||
type Config struct { | ||
Protocol string `mapstructure:"protocol"` | ||
Version string `mapstructure:"version"` | ||
} | ||
|
||
func (c *Config) Validate() error { | ||
if c.Protocol != zipkinProtobufEncoding && c.Protocol != zipkinJSONEncoding && c.Protocol != zipkinThriftEncoding { | ||
return fmt.Errorf("unsupported protocol: %q", c.Protocol) | ||
} | ||
if c.Version != v1 && c.Version != v2 { | ||
return fmt.Errorf("unsupported version: %q", c.Version) | ||
} | ||
|
||
return 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
//go:generate mdatagen metadata.yaml | ||
package zipkinencodingextension // import "github.com/open-telemetry/opentelemetry-collector-contrib/extension/encoding/zipkinencodingextension" |
106 changes: 106 additions & 0 deletions
106
extension/encoding/zipkinencodingextension/extension.go
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,106 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package zipkinencodingextension // import "github.com/open-telemetry/opentelemetry-collector-contrib/extension/encoding/zipkinencodingextension" | ||
|
||
import ( | ||
"context" | ||
"errors" | ||
"fmt" | ||
|
||
"go.opentelemetry.io/collector/component" | ||
"go.opentelemetry.io/collector/pdata/ptrace" | ||
|
||
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/zipkin/zipkinv1" | ||
"github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/zipkin/zipkinv2" | ||
) | ||
|
||
const ( | ||
zipkinProtobufEncoding = "zipkin_proto" | ||
zipkinJSONEncoding = "zipkin_json" | ||
zipkinThriftEncoding = "zipkin_thrift" | ||
v1 = "v1" | ||
v2 = "v2" | ||
) | ||
|
||
var ( | ||
_ ptrace.Marshaler = (*zipkinExtension)(nil) | ||
_ ptrace.Unmarshaler = (*zipkinExtension)(nil) | ||
) | ||
|
||
type zipkinExtension struct { | ||
config *Config | ||
marshaler ptrace.Marshaler | ||
unmarshaler ptrace.Unmarshaler | ||
} | ||
|
||
func newExtension(config *Config) (*zipkinExtension, error) { | ||
var err error | ||
var ex *zipkinExtension | ||
|
||
protocol := config.Protocol | ||
version := config.Version | ||
switch protocol { | ||
case zipkinProtobufEncoding: | ||
switch version { | ||
case v2: | ||
ex = &zipkinExtension{ | ||
config: config, | ||
marshaler: zipkinv2.NewProtobufTracesMarshaler(), | ||
unmarshaler: zipkinv2.NewProtobufTracesUnmarshaler(false, false), | ||
} | ||
default: | ||
err = fmt.Errorf("unsupported version: %q and protocol: %q", version, protocol) | ||
} | ||
case zipkinJSONEncoding: | ||
switch version { | ||
case v1: | ||
ex = &zipkinExtension{ | ||
config: config, | ||
marshaler: nil, | ||
unmarshaler: zipkinv1.NewJSONTracesUnmarshaler(false), | ||
} | ||
case v2: | ||
ex = &zipkinExtension{ | ||
config: config, | ||
marshaler: zipkinv2.NewJSONTracesMarshaler(), | ||
unmarshaler: zipkinv2.NewJSONTracesUnmarshaler(false), | ||
} | ||
} | ||
case zipkinThriftEncoding: | ||
switch version { | ||
case v1: | ||
ex = &zipkinExtension{ | ||
config: config, | ||
marshaler: nil, | ||
unmarshaler: zipkinv1.NewThriftTracesUnmarshaler(), | ||
} | ||
default: | ||
err = fmt.Errorf("unsupported version: %q and protocol: %q", version, protocol) | ||
} | ||
} | ||
|
||
return ex, err | ||
} | ||
|
||
func (ex *zipkinExtension) Start(_ context.Context, _ component.Host) error { | ||
return nil | ||
} | ||
|
||
func (ex *zipkinExtension) Shutdown(_ context.Context) error { | ||
return nil | ||
} | ||
|
||
func (ex *zipkinExtension) UnmarshalTraces(buf []byte) (ptrace.Traces, error) { | ||
if ex.unmarshaler == nil { | ||
return ptrace.Traces{}, errors.New("unsupported encoding") | ||
} | ||
return ex.unmarshaler.UnmarshalTraces(buf) | ||
} | ||
|
||
func (ex *zipkinExtension) MarshalTraces(td ptrace.Traces) ([]byte, error) { | ||
if ex.unmarshaler == nil { | ||
return nil, errors.New("unsupported encoding") | ||
} | ||
return ex.marshaler.MarshalTraces(td) | ||
} |
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,30 @@ | ||
// Copyright The OpenTelemetry Authors | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package zipkinencodingextension // import "github.com/open-telemetry/opentelemetry-collector-contrib/extension/encoding/zipkinencodingextension" | ||
|
||
import ( | ||
"context" | ||
|
||
"go.opentelemetry.io/collector/component" | ||
"go.opentelemetry.io/collector/extension" | ||
|
||
"github.com/open-telemetry/opentelemetry-collector-contrib/extension/encoding/zipkinencodingextension/internal/metadata" | ||
) | ||
|
||
func NewFactory() extension.Factory { | ||
return extension.NewFactory( | ||
metadata.Type, | ||
createDefaultConfig, | ||
createExtension, | ||
metadata.ExtensionStability, | ||
) | ||
} | ||
|
||
func createExtension(_ context.Context, _ extension.CreateSettings, config component.Config) (extension.Extension, error) { | ||
return newExtension(config.(*Config)) | ||
} | ||
|
||
func createDefaultConfig() component.Config { | ||
return &Config{Protocol: zipkinProtobufEncoding, Version: v2} | ||
} |
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,55 @@ | ||
module github.com/open-telemetry/opentelemetry-collector-contrib/extension/encoding/zipkinencodingextension | ||
|
||
go 1.20 | ||
|
||
require ( | ||
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/zipkin v0.87.1-0.20231017160804-ec0725874313 | ||
go.opentelemetry.io/collector/component v0.87.1-0.20231017160804-ec0725874313 | ||
go.opentelemetry.io/collector/extension v0.87.1-0.20231017160804-ec0725874313 | ||
go.opentelemetry.io/collector/pdata v1.0.0-rcv0016.0.20231017160804-ec0725874313 | ||
) | ||
|
||
require ( | ||
github.com/apache/thrift v0.19.0 // indirect | ||
github.com/gogo/protobuf v1.3.2 // indirect | ||
github.com/golang/protobuf v1.5.3 // indirect | ||
github.com/jaegertracing/jaeger v1.48.0 // indirect | ||
github.com/json-iterator/go v1.1.12 // indirect | ||
github.com/knadh/koanf/maps v0.1.1 // indirect | ||
github.com/knadh/koanf/providers/confmap v0.1.0 // indirect | ||
github.com/knadh/koanf/v2 v2.0.1 // indirect | ||
github.com/mitchellh/copystructure v1.2.0 // indirect | ||
github.com/mitchellh/mapstructure v1.5.1-0.20220423185008-bf980b35cac4 // indirect | ||
github.com/mitchellh/reflectwalk v1.0.2 // indirect | ||
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect | ||
github.com/modern-go/reflect2 v1.0.2 // indirect | ||
github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal v0.87.0 // indirect | ||
github.com/opentracing/opentracing-go v1.2.0 // indirect | ||
github.com/openzipkin/zipkin-go v0.4.2 // indirect | ||
github.com/uber/jaeger-client-go v2.30.0+incompatible // indirect | ||
github.com/uber/jaeger-lib v2.4.1+incompatible // indirect | ||
go.opentelemetry.io/collector/config/configtelemetry v0.87.1-0.20231017160804-ec0725874313 // indirect | ||
go.opentelemetry.io/collector/confmap v0.87.1-0.20231017160804-ec0725874313 // indirect | ||
go.opentelemetry.io/collector/featuregate v1.0.0-rcv0016.0.20231017160804-ec0725874313 // indirect | ||
go.opentelemetry.io/collector/semconv v0.87.1-0.20231017160804-ec0725874313 // indirect | ||
go.opentelemetry.io/otel v1.19.0 // indirect | ||
go.opentelemetry.io/otel/metric v1.19.0 // indirect | ||
go.opentelemetry.io/otel/trace v1.19.0 // indirect | ||
go.uber.org/atomic v1.11.0 // indirect | ||
go.uber.org/multierr v1.11.0 // indirect | ||
go.uber.org/zap v1.26.0 // indirect | ||
golang.org/x/net v0.17.0 // indirect | ||
golang.org/x/sys v0.13.0 // indirect | ||
golang.org/x/text v0.13.0 // indirect | ||
google.golang.org/genproto/googleapis/rpc v0.0.0-20230711160842-782d3b101e98 // indirect | ||
google.golang.org/grpc v1.58.3 // indirect | ||
google.golang.org/protobuf v1.31.0 // indirect | ||
) | ||
|
||
replace github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal => ../../../internal/coreinternal | ||
|
||
replace github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/zipkin => ../../../pkg/translator/zipkin | ||
|
||
replace github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatautil => ../../../pkg/pdatautil | ||
|
||
replace github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatatest => ../../../pkg/pdatatest |
Oops, something went wrong.