Skip to content

Commit

Permalink
[extension/encoding] support skywalkingencoding extension (open-telem…
Browse files Browse the repository at this point in the history
…etry#36968)

<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue.
Ex. Adding a feature - Explain what this achieves.-->
#### Description
The `kafkareceiver` supports `jaeger` and `zipkin` protocol traces, and
can also receive skywalkng traces via `skywalkingreceiver`.

From the practical use of skywalking, we often use kafka to host
large-scale traces data. However, `kafka receiver` does not support
`skywalking encoding` currently.

with this PR, we can fectch skywalking traces and parse it into `otlp`
traces:

```yaml
receivers:
  otlp:
    protocols:
      grpc:
        endpoint: 0.0.0.0:4317
  kafka:
    encoding: skywalking_encoding
    topic: skywalking-segments
    brokers:
      - "localhost:9092"
    resolve_canonical_bootstrap_servers_only: true
    client_id: otel-collector
    group_id: otel-collector
    metadata:
      retry:
        max: 10
        backoff: 5s

exporters:
  debug:

processors:
  batch:

extensions:
  health_check:
  pprof:
    endpoint: :1888
  zpages:
    endpoint: :55679
  skywalking_encoding:

service:
  extensions: [pprof, zpages, skywalking_encoding, health_check]
  pipelines:
    traces:
      receivers: [kafka]
      processors: [batch]
      exporters: [debug]
```


<!-- Issue number (e.g. open-telemetry#1234) or full URL to issue, if applicable. -->
#### Link to tracking issue
Fixes
open-telemetry#28693

<!--Describe what testing was performed and which tests were added.-->
#### Testing

<!--Describe the documentation added.-->
#### Documentation

<!--Please delete paragraphs that you did not use before submitting.-->

---------

Signed-off-by: Jared Tan <[email protected]>
Co-authored-by: Tyler Helmuth <[email protected]>
  • Loading branch information
2 people authored and chengchuanpeng committed Jan 26, 2025
1 parent 93c4303 commit a357b6e
Show file tree
Hide file tree
Showing 21 changed files with 695 additions and 0 deletions.
27 changes: 27 additions & 0 deletions .chloggen/support_skywalking_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: extension/skywalkingencodingextension

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Support skywalking_encoding extension for skywalking traces.

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [28693]

# (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
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ extension/encoding/avrologencodingextension/ @open-telemetry/collector-cont
extension/encoding/jaegerencodingextension/ @open-telemetry/collector-contrib-approvers @MovieStoreGuy @atoulme
extension/encoding/jsonlogencodingextension/ @open-telemetry/collector-contrib-approvers @VihasMakwana @atoulme
extension/encoding/otlpencodingextension/ @open-telemetry/collector-contrib-approvers @dao-jun @VihasMakwana
extension/encoding/skywalkingencodingextension/ @open-telemetry/collector-contrib-approvers @JaredTan95
extension/encoding/textencodingextension/ @open-telemetry/collector-contrib-approvers @MovieStoreGuy @atoulme
extension/encoding/zipkinencodingextension/ @open-telemetry/collector-contrib-approvers @MovieStoreGuy @dao-jun
extension/googleclientauthextension/ @open-telemetry/collector-contrib-approvers @dashpole @aabmass @jsuereth @punya @psx95
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 @@ -96,6 +96,7 @@ body:
- extension/encoding/jaegerencoding
- extension/encoding/jsonlogencoding
- extension/encoding/otlpencoding
- extension/encoding/skywalkingencoding
- extension/encoding/textencoding
- extension/encoding/zipkinencoding
- extension/googleclientauth
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 @@ -90,6 +90,7 @@ body:
- extension/encoding/jaegerencoding
- extension/encoding/jsonlogencoding
- extension/encoding/otlpencoding
- extension/encoding/skywalkingencoding
- extension/encoding/textencoding
- extension/encoding/zipkinencoding
- extension/googleclientauth
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 @@ -90,6 +90,7 @@ body:
- extension/encoding/jaegerencoding
- extension/encoding/jsonlogencoding
- extension/encoding/otlpencoding
- extension/encoding/skywalkingencoding
- extension/encoding/textencoding
- extension/encoding/zipkinencoding
- extension/googleclientauth
Expand Down
1 change: 1 addition & 0 deletions .github/ISSUE_TEMPLATE/unmaintained.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ body:
- extension/encoding/jaegerencoding
- extension/encoding/jsonlogencoding
- extension/encoding/otlpencoding
- extension/encoding/skywalkingencoding
- extension/encoding/textencoding
- extension/encoding/zipkinencoding
- extension/googleclientauth
Expand Down
2 changes: 2 additions & 0 deletions cmd/otelcontribcol/builder-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ extensions:
- gomod: github.com/open-telemetry/opentelemetry-collector-contrib/extension/encoding/jsonlogencodingextension v0.117.0
- gomod: github.com/open-telemetry/opentelemetry-collector-contrib/extension/encoding/textencodingextension v0.117.0
- gomod: github.com/open-telemetry/opentelemetry-collector-contrib/extension/encoding/zipkinencodingextension v0.117.0
- gomod: github.com/open-telemetry/opentelemetry-collector-contrib/extension/encoding/skywalkingencodingextension v0.117.0

exporters:
- gomod: go.opentelemetry.io/collector/exporter/debugexporter v0.117.0
Expand Down Expand Up @@ -483,6 +484,7 @@ replaces:
- github.com/open-telemetry/opentelemetry-collector-contrib/extension/encoding/avrologencodingextension => ../../extension/encoding/avrologencodingextension
- github.com/open-telemetry/opentelemetry-collector-contrib/extension/encoding/jsonlogencodingextension => ../../extension/encoding/jsonlogencodingextension
- github.com/open-telemetry/opentelemetry-collector-contrib/extension/encoding/textencodingextension => ../../extension/encoding/textencodingextension
- github.com/open-telemetry/opentelemetry-collector-contrib/extension/encoding/skywalkingencodingextension => ../../extension/encoding/skywalkingencodingextension
- github.com/open-telemetry/opentelemetry-collector-contrib/extension/encoding/jaegerencodingextension => ../../extension/encoding/jaegerencodingextension
- github.com/open-telemetry/opentelemetry-collector-contrib/extension/remotetapextension => ../../extension/remotetapextension
- github.com/open-telemetry/opentelemetry-collector-contrib/extension/opampextension => ../../extension/opampextension
Expand Down
1 change: 1 addition & 0 deletions extension/encoding/skywalkingencodingextension/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include ../../../Makefile.Common
27 changes: 27 additions & 0 deletions extension/encoding/skywalkingencodingextension/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Skywalking encoding extension

<!-- status autogenerated section -->
| Status | |
| ------------- |---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Stability | [alpha] |
| Distributions | [] |
| Issues | [![Open issues](https://img.shields.io/github/issues-search/open-telemetry/opentelemetry-collector-contrib?query=is%3Aissue%20is%3Aopen%20label%3Aextension%2Fskywalkingencodingextension%20&label=open&color=orange&logo=opentelemetry)](https://github.com/open-telemetry/opentelemetry-collector-contrib/issues?q=is%3Aopen+is%3Aissue+label%3Aextension%2Fskywalkingencodingextension) [![Closed issues](https://img.shields.io/github/issues-search/open-telemetry/opentelemetry-collector-contrib?query=is%3Aissue%20is%3Aclosed%20label%3Aextension%2Fskywalkingencodingextension%20&label=closed&color=blue&logo=opentelemetry)](https://github.com/open-telemetry/opentelemetry-collector-contrib/issues?q=is%3Aclosed+is%3Aissue+label%3Aextension%2Fskywalkingencodingextension) |
| [Code Owners](https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/CONTRIBUTING.md#becoming-a-code-owner) | [@JaredTan95](https://www.github.com/JaredTan95) |

[alpha]: https://github.com/open-telemetry/opentelemetry-collector/blob/main/docs/component-stability.md#alpha
<!-- end autogenerated section -->

The `Skywalking` encoding extension is used to unmarshal Apache Skywalking segment traces. Marshalling is not supported.

## Example configuration

```yaml
extensions:
skywalking_encoding:

receivers:
kafka:
encoding: skywalking_encoding
```
The detailed sample configurations [here](./testdata).
27 changes: 27 additions & 0 deletions extension/encoding/skywalkingencodingextension/extension.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 skywalkingencodingextension // import "github.com/open-telemetry/opentelemetry-collector-contrib/extension/encoding/skywalkingencodingextension"

import (
"context"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/pdata/ptrace"
)

type skywalkingExtension struct {
unmarshaler ptrace.Unmarshaler
}

func (e *skywalkingExtension) UnmarshalTraces(buf []byte) (ptrace.Traces, error) {
return e.unmarshaler.UnmarshalTraces(buf)
}

func (e *skywalkingExtension) Start(_ context.Context, _ component.Host) error {
return nil
}

func (e *skywalkingExtension) Shutdown(_ context.Context) error {
return nil
}
47 changes: 47 additions & 0 deletions extension/encoding/skywalkingencodingextension/extension_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

package skywalkingencodingextension

import (
"context"
"testing"

"github.com/stretchr/testify/require"
"go.opentelemetry.io/collector/component/componenttest"
"go.opentelemetry.io/collector/extension"
"go.opentelemetry.io/collector/extension/extensiontest"
)

func TestExtension_Start(t *testing.T) {
tests := []struct {
name string
getExtension func() (extension.Extension, error)
expectedErr string
}{
{
name: "skywalkingProtobuf",
getExtension: func() (extension.Extension, error) {
factory := NewFactory()
cfg := factory.CreateDefaultConfig()
return factory.Create(context.Background(), extensiontest.NewNopSettings(), cfg)
},
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
ext, err := test.getExtension()
if test.expectedErr != "" && err != nil {
require.ErrorContains(t, err, test.expectedErr)
} else {
require.NoError(t, err)
}
err = ext.Start(context.Background(), componenttest.NewNopHost())
if test.expectedErr != "" && err != nil {
require.ErrorContains(t, err, test.expectedErr)
} else {
require.NoError(t, err)
}
})
}
}
32 changes: 32 additions & 0 deletions extension/encoding/skywalkingencodingextension/factory.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

package skywalkingencodingextension // import "github.com/open-telemetry/opentelemetry-collector-contrib/extension/encoding/skywalkingencodingextension"

import (
"context"

"go.opentelemetry.io/collector/component"
"go.opentelemetry.io/collector/extension"

"github.com/open-telemetry/opentelemetry-collector-contrib/extension/encoding/skywalkingencodingextension/internal/metadata"
)

func NewFactory() extension.Factory {
return extension.NewFactory(
metadata.Type,
createDefaultConfig,
createExtension,
metadata.ExtensionStability,
)
}

func createExtension(_ context.Context, _ extension.Settings, _ component.Config) (extension.Extension, error) {
return &skywalkingExtension{
unmarshaler: skywalkingProtobufTrace{},
}, nil
}

func createDefaultConfig() component.Config {
return nil
}
44 changes: 44 additions & 0 deletions extension/encoding/skywalkingencodingextension/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
module github.com/open-telemetry/opentelemetry-collector-contrib/extension/encoding/skywalkingencodingextension

go 1.22.0

require (
github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/skywalking v0.117.0
github.com/stretchr/testify v1.10.0
go.opentelemetry.io/collector/component v0.117.1-0.20250114172347-71aae791d7f8
go.opentelemetry.io/collector/component/componenttest v0.117.0
go.opentelemetry.io/collector/extension v0.117.1-0.20250114172347-71aae791d7f8
go.opentelemetry.io/collector/extension/extensiontest v0.117.0
go.opentelemetry.io/collector/pdata v1.23.1-0.20250114172347-71aae791d7f8
google.golang.org/protobuf v1.36.2
skywalking.apache.org/repo/goapi v0.0.0-20240104145220-ba7202308dd4
)

require (
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
go.opentelemetry.io/collector/config/configtelemetry v0.117.1-0.20250114172347-71aae791d7f8 // indirect
go.opentelemetry.io/collector/semconv v0.117.1-0.20250114172347-71aae791d7f8 // indirect
go.opentelemetry.io/otel v1.32.0 // indirect
go.opentelemetry.io/otel/metric v1.32.0 // indirect
go.opentelemetry.io/otel/sdk v1.32.0 // indirect
go.opentelemetry.io/otel/sdk/metric v1.32.0 // indirect
go.opentelemetry.io/otel/trace v1.32.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.uber.org/zap v1.27.0 // indirect
golang.org/x/net v0.33.0 // indirect
golang.org/x/sys v0.28.0 // indirect
golang.org/x/text v0.21.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20241015192408-796eee8c2d53 // indirect
google.golang.org/grpc v1.69.4 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

replace github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/skywalking => ../../../pkg/translator/skywalking
Loading

0 comments on commit a357b6e

Please sign in to comment.