Skip to content

Commit

Permalink
[extension/encodingextension] Introduce zipkin encoding extension. (o…
Browse files Browse the repository at this point in the history
…pen-telemetry#27877)

Introduce zipkin encoding extension.
For more context, see
open-telemetry#27564
  • Loading branch information
dao-jun authored Oct 24, 2023
1 parent d83a322 commit 4241ab5
Show file tree
Hide file tree
Showing 17 changed files with 424 additions and 10 deletions.
27 changes: 27 additions & 0 deletions .chloggen/zipkin_encoding_extension.yaml
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: []
1 change: 1 addition & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ extension/bearertokenauthextension/ @open-te
extension/encoding/jaegerencodingextension/ @open-telemetry/collector-contrib-approvers @MovieStoreGuy @atoulme
extension/encoding/jsonlogencodingextension/ @open-telemetry/collector-contrib-approvers @VihasMakwana @atoulme
extension/encoding/textencodingextension/ @open-telemetry/collector-contrib-approvers @MovieStoreGuy @atoulme
extension/encoding/zipkinencodingextension/ @open-telemetry/collector-contrib-approvers @MovieStoreGuy @dao-jun
extension/headerssetterextension/ @open-telemetry/collector-contrib-approvers @jpkrohling
extension/healthcheckextension/ @open-telemetry/collector-contrib-approvers @jpkrohling
extension/httpforwarder/ @open-telemetry/collector-contrib-approvers @atoulme @rmfitzpatrick
Expand Down
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/bug_report.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ body:
- extension/encoding/jaegerencoding
- extension/encoding/jsonlogencoding
- extension/encoding/textencoding
- extension/encoding/zipkinencoding
- extension/headerssetter
- extension/healthcheck
- extension/httpforwarder
Expand Down
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/feature_request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ body:
- extension/encoding/jaegerencoding
- extension/encoding/jsonlogencoding
- extension/encoding/textencoding
- extension/encoding/zipkinencoding
- extension/headerssetter
- extension/healthcheck
- extension/httpforwarder
Expand Down
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/other.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ body:
- extension/encoding/jaegerencoding
- extension/encoding/jsonlogencoding
- extension/encoding/textencoding
- extension/encoding/zipkinencoding
- extension/headerssetter
- extension/healthcheck
- extension/httpforwarder
Expand Down
20 changes: 10 additions & 10 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@ updates:
schedule:
interval: "weekly"
day: "wednesday"
- package-ecosystem: "gomod"
directory: "/cmd/configschema"
schedule:
interval: "weekly"
day: "wednesday"
- package-ecosystem: "gomod"
directory: "/cmd/otelcontribcol"
schedule:
Expand Down Expand Up @@ -272,6 +267,11 @@ updates:
schedule:
interval: "weekly"
day: "wednesday"
- package-ecosystem: "gomod"
directory: "/exporter/syslogexporter"
schedule:
interval: "weekly"
day: "wednesday"
- package-ecosystem: "gomod"
directory: "/exporter/tanzuobservabilityexporter"
schedule:
Expand Down Expand Up @@ -307,6 +307,11 @@ updates:
schedule:
interval: "weekly"
day: "wednesday"
- package-ecosystem: "gomod"
directory: "/extension/encoding/jaegerencodingextension"
schedule:
interval: "weekly"
day: "wednesday"
- package-ecosystem: "gomod"
directory: "/extension/headerssetterextension"
schedule:
Expand Down Expand Up @@ -1062,11 +1067,6 @@ updates:
schedule:
interval: "weekly"
day: "wednesday"
- package-ecosystem: "gomod"
directory: "/receiver/webhookeventreceiver"
schedule:
interval: "weekly"
day: "wednesday"
- package-ecosystem: "gomod"
directory: "/receiver/windowseventlogreceiver"
schedule:
Expand Down
1 change: 1 addition & 0 deletions extension/encoding/zipkinencodingextension/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include ../../../Makefile.Common
12 changes: 12 additions & 0 deletions extension/encoding/zipkinencodingextension/README.md
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 -->
27 changes: 27 additions & 0 deletions extension/encoding/zipkinencodingextension/config.go
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
}
5 changes: 5 additions & 0 deletions extension/encoding/zipkinencodingextension/doc.go
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 extension/encoding/zipkinencodingextension/extension.go
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)
}
30 changes: 30 additions & 0 deletions extension/encoding/zipkinencodingextension/factory.go
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}
}
55 changes: 55 additions & 0 deletions extension/encoding/zipkinencodingextension/go.mod
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
Loading

0 comments on commit 4241ab5

Please sign in to comment.