Skip to content
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

[receiver/libhoney] Libhoney receiver log signal #36827

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions .chloggen/logs-for-libhoneyreceiver.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: enhancement

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: libhoneyreceiver

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: Implement log signal for libhoney receiver

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

# (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: [user]
29 changes: 15 additions & 14 deletions receiver/libhoneyreceiver/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,21 @@ The following setting is required for refinery traffic since:
- "/1/batch"
include_metadata: true
auth_api: https://api.honeycomb.io
resources:
service_name: service_name
scopes:
library_name: library.name
library_version: library.version
attributes:
trace_id: trace_id
parent_id: parent_id
span_id: span_id
name: name
error: error
spankind: span.kind
durationFields:
- duration_ms
fields:
resources:
service_name: service_name
scopes:
library_name: library.name
library_version: library.version
attributes:
trace_id: trace_id
parent_id: parent_id
span_id: span_id
name: name
error: error
spankind: span.kind
durationFields:
- duration_ms
```

### Telemetry data types supported
Expand Down
34 changes: 9 additions & 25 deletions receiver/libhoneyreceiver/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,51 +11,35 @@ import (

"go.opentelemetry.io/collector/config/confighttp"
"go.opentelemetry.io/collector/confmap"

"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/libhoneyreceiver/internal/libhoneyevent"
)

// Config represents the receiver config settings within the collector's config.yaml
type Config struct {
HTTP *HTTPConfig `mapstructure:"http"`
AuthAPI string `mapstructure:"auth_api"`
Wrapper string `mapstructure:"wrapper"`
Resources ResourcesConfig `mapstructure:"resources"`
Scopes ScopesConfig `mapstructure:"scopes"`
Attributes AttributesConfig `mapstructure:"attributes"`
HTTP *HTTPConfig `mapstructure:"http"`
AuthAPI string `mapstructure:"auth_api"`
Wrapper string `mapstructure:"wrapper"`
FieldMapConfig libhoneyevent.FieldMapConfig `mapstructure:"fields"`
}

// HTTPConfig defines the configuration for the HTTP server receiving traces.
type HTTPConfig struct {
*confighttp.ServerConfig `mapstructure:",squash"`

// The URL path to receive traces on. If omitted "/" will be used.
TracesURLPaths []string `mapstructure:"traces_url_paths,omitempty"`
}

type ResourcesConfig struct {
ServiceName string `mapstructure:"service_name"`
}

type ScopesConfig struct {
LibraryName string `mapstructure:"library_name"`
LibraryVersion string `mapstructure:"library_version"`
}

type AttributesConfig struct {
TraceID string `mapstructure:"trace_id"`
ParentID string `mapstructure:"parent_id"`
SpanID string `mapstructure:"span_id"`
Name string `mapstructure:"name"`
Error string `mapstructure:"error"`
SpanKind string `mapstructure:"spankind"`
DurationFields []string `mapstructure:"durationFields"`
}

// Validate ensures the HTTP configuration is set.
func (cfg *Config) Validate() error {
if cfg.HTTP == nil {
return errors.New("must specify at least one protocol when using the arbitrary JSON receiver")
}
return nil
}

// Unmarshal unmarshals the configuration from the given configuration and then checks for errors.
func (cfg *Config) Unmarshal(conf *confmap.Conf) error {
// first load the config normally
err := conf.Unmarshal(cfg)
Expand Down
125 changes: 125 additions & 0 deletions receiver/libhoneyreceiver/encoder/encoder.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

package encoder // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/libhoneyreceiver/encoder"

import (
"bytes"

"github.com/gogo/protobuf/jsonpb"
"go.opentelemetry.io/collector/pdata/plog/plogotlp"
"go.opentelemetry.io/collector/pdata/pmetric/pmetricotlp"
"go.opentelemetry.io/collector/pdata/ptrace/ptraceotlp"
spb "google.golang.org/genproto/googleapis/rpc/status"
)

const (
PbContentType = "application/x-protobuf"
JsonContentType = "application/json"
MsgpackContentType = "application/x-msgpack"
)

var (
JsEncoder = &JsonEncoder{}
JsonPbMarshaler = &jsonpb.Marshaler{}
MpEncoder = &msgpackEncoder{}
)

type Encoder interface {
UnmarshalTracesRequest(buf []byte) (ptraceotlp.ExportRequest, error)
UnmarshalMetricsRequest(buf []byte) (pmetricotlp.ExportRequest, error)
UnmarshalLogsRequest(buf []byte) (plogotlp.ExportRequest, error)

MarshalTracesResponse(ptraceotlp.ExportResponse) ([]byte, error)
MarshalMetricsResponse(pmetricotlp.ExportResponse) ([]byte, error)
MarshalLogsResponse(plogotlp.ExportResponse) ([]byte, error)

MarshalStatus(rsp *spb.Status) ([]byte, error)

ContentType() string
}

type JsonEncoder struct{}

func (JsonEncoder) UnmarshalTracesRequest(buf []byte) (ptraceotlp.ExportRequest, error) {
req := ptraceotlp.NewExportRequest()
err := req.UnmarshalJSON(buf)
return req, err
}

func (JsonEncoder) UnmarshalMetricsRequest(buf []byte) (pmetricotlp.ExportRequest, error) {
req := pmetricotlp.NewExportRequest()
err := req.UnmarshalJSON(buf)
return req, err
}

func (JsonEncoder) UnmarshalLogsRequest(buf []byte) (plogotlp.ExportRequest, error) {
req := plogotlp.NewExportRequest()
err := req.UnmarshalJSON(buf)
return req, err
}

func (JsonEncoder) MarshalTracesResponse(resp ptraceotlp.ExportResponse) ([]byte, error) {
return resp.MarshalJSON()
}

func (JsonEncoder) MarshalMetricsResponse(resp pmetricotlp.ExportResponse) ([]byte, error) {
return resp.MarshalJSON()
}

func (JsonEncoder) MarshalLogsResponse(resp plogotlp.ExportResponse) ([]byte, error) {
return resp.MarshalJSON()
}

func (JsonEncoder) MarshalStatus(resp *spb.Status) ([]byte, error) {
buf := new(bytes.Buffer)
err := JsonPbMarshaler.Marshal(buf, resp)
return buf.Bytes(), err
}

func (JsonEncoder) ContentType() string {
return JsonContentType
}

// messagepack responses seem to work in JSON so leaving this alone for now.
type msgpackEncoder struct{}

func (msgpackEncoder) UnmarshalTracesRequest(buf []byte) (ptraceotlp.ExportRequest, error) {
req := ptraceotlp.NewExportRequest()
err := req.UnmarshalJSON(buf)
return req, err
}

func (msgpackEncoder) UnmarshalMetricsRequest(buf []byte) (pmetricotlp.ExportRequest, error) {
req := pmetricotlp.NewExportRequest()
err := req.UnmarshalJSON(buf)
return req, err
}

func (msgpackEncoder) UnmarshalLogsRequest(buf []byte) (plogotlp.ExportRequest, error) {
req := plogotlp.NewExportRequest()
err := req.UnmarshalJSON(buf)
return req, err
}

func (msgpackEncoder) MarshalTracesResponse(resp ptraceotlp.ExportResponse) ([]byte, error) {
return resp.MarshalJSON()
}

func (msgpackEncoder) MarshalMetricsResponse(resp pmetricotlp.ExportResponse) ([]byte, error) {
return resp.MarshalJSON()
}

func (msgpackEncoder) MarshalLogsResponse(resp plogotlp.ExportResponse) ([]byte, error) {
return resp.MarshalJSON()
}

func (msgpackEncoder) MarshalStatus(resp *spb.Status) ([]byte, error) {
buf := new(bytes.Buffer)
err := JsonPbMarshaler.Marshal(buf, resp)
return buf.Bytes(), err
}

func (msgpackEncoder) ContentType() string {
return MsgpackContentType
}
33 changes: 18 additions & 15 deletions receiver/libhoneyreceiver/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"go.opentelemetry.io/collector/receiver"

"github.com/open-telemetry/opentelemetry-collector-contrib/internal/sharedcomponent"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/libhoneyreceiver/internal/libhoneyevent"
"github.com/open-telemetry/opentelemetry-collector-contrib/receiver/libhoneyreceiver/internal/metadata"
)

Expand Down Expand Up @@ -44,21 +45,23 @@ func createDefaultConfig() component.Config {
TracesURLPaths: defaultTracesURLPaths,
},
AuthAPI: "",
Resources: ResourcesConfig{
ServiceName: "service.name",
},
Scopes: ScopesConfig{
LibraryName: "library.name",
LibraryVersion: "library.version",
},
Attributes: AttributesConfig{
TraceID: "trace.trace_id",
SpanID: "trace.span_id",
ParentID: "trace.parent_id",
Name: "name",
Error: "error",
SpanKind: "span.kind",
DurationFields: durationFieldsArr,
FieldMapConfig: libhoneyevent.FieldMapConfig{
Resources: libhoneyevent.ResourcesConfig{
ServiceName: "service.name",
},
Scopes: libhoneyevent.ScopesConfig{
LibraryName: "library.name",
LibraryVersion: "library.version",
},
Attributes: libhoneyevent.AttributesConfig{
TraceID: "trace.trace_id",
SpanID: "trace.span_id",
ParentID: "trace.parent_id",
Name: "name",
Error: "error",
SpanKind: "span.kind",
DurationFields: durationFieldsArr,
},
},
}
}
Expand Down
32 changes: 22 additions & 10 deletions receiver/libhoneyreceiver/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,25 @@ module github.com/open-telemetry/opentelemetry-collector-contrib/receiver/libhon
go 1.22.0

require (
github.com/gogo/protobuf v1.3.2
github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal v0.115.0
github.com/open-telemetry/opentelemetry-collector-contrib/internal/sharedcomponent v0.115.0
github.com/stretchr/testify v1.10.0
github.com/vmihailenco/msgpack/v5 v5.4.1
go.opentelemetry.io/collector/component v0.115.1-0.20241206185113-3f3e208e71b8
go.opentelemetry.io/collector/component/componentstatus v0.115.1-0.20241206185113-3f3e208e71b8
go.opentelemetry.io/collector/component/componenttest v0.115.1-0.20241206185113-3f3e208e71b8
go.opentelemetry.io/collector/config/confighttp v0.115.1-0.20241206185113-3f3e208e71b8
go.opentelemetry.io/collector/confmap v1.21.1-0.20241206185113-3f3e208e71b8
go.opentelemetry.io/collector/consumer v1.21.1-0.20241206185113-3f3e208e71b8
go.opentelemetry.io/collector/consumer/consumertest v0.115.1-0.20241206185113-3f3e208e71b8
go.opentelemetry.io/collector/pdata v1.21.1-0.20241206185113-3f3e208e71b8
go.opentelemetry.io/collector/receiver v0.115.1-0.20241206185113-3f3e208e71b8
go.opentelemetry.io/collector/receiver/receivertest v0.115.1-0.20241206185113-3f3e208e71b8
go.opentelemetry.io/collector/semconv v0.115.1-0.20241206185113-3f3e208e71b8
go.uber.org/goleak v1.3.0
go.uber.org/zap v1.27.0
google.golang.org/genproto/googleapis/rpc v0.0.0-20241007155032-5fefd90f89a9
)

require (
Expand All @@ -20,7 +31,6 @@ require (
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-viper/mapstructure/v2 v2.2.1 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
Expand All @@ -32,27 +42,23 @@ require (
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/sharedcomponent v0.115.0
github.com/pierrec/lz4/v4 v4.1.21 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rs/cors v1.11.1 // indirect
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
go.opentelemetry.io/collector/client v1.21.1-0.20241206185113-3f3e208e71b8 // indirect
go.opentelemetry.io/collector/component v0.115.1-0.20241206185113-3f3e208e71b8
go.opentelemetry.io/collector/component/componentstatus v0.115.1-0.20241206185113-3f3e208e71b8
go.opentelemetry.io/collector/config/configauth v0.115.1-0.20241206185113-3f3e208e71b8 // indirect
go.opentelemetry.io/collector/config/configcompression v1.21.1-0.20241206185113-3f3e208e71b8 // indirect
go.opentelemetry.io/collector/config/configopaque v1.21.1-0.20241206185113-3f3e208e71b8 // indirect
go.opentelemetry.io/collector/config/configtelemetry v0.115.1-0.20241206185113-3f3e208e71b8 // indirect
go.opentelemetry.io/collector/config/configtls v1.21.1-0.20241206185113-3f3e208e71b8 // indirect
go.opentelemetry.io/collector/config/internal v0.115.0 // indirect
go.opentelemetry.io/collector/consumer/consumererror v0.115.0 // indirect
go.opentelemetry.io/collector/consumer/consumererror v0.115.1-0.20241206185113-3f3e208e71b8 // indirect
go.opentelemetry.io/collector/consumer/consumerprofiles v0.115.1-0.20241206185113-3f3e208e71b8 // indirect
go.opentelemetry.io/collector/extension v0.115.1-0.20241206185113-3f3e208e71b8 // indirect
go.opentelemetry.io/collector/extension/auth v0.115.1-0.20241206185113-3f3e208e71b8 // indirect
go.opentelemetry.io/collector/pdata v1.21.1-0.20241206185113-3f3e208e71b8 // indirect
go.opentelemetry.io/collector/pdata/pprofile v0.115.1-0.20241206185113-3f3e208e71b8 // indirect
go.opentelemetry.io/collector/pipeline v0.115.1-0.20241206185113-3f3e208e71b8 // indirect
go.opentelemetry.io/collector/receiver v0.115.1-0.20241206185113-3f3e208e71b8
go.opentelemetry.io/collector/receiver/receiverprofiles v0.115.1-0.20241206185113-3f3e208e71b8 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.56.0 // indirect
go.opentelemetry.io/otel v1.32.0 // indirect
Expand All @@ -61,16 +67,22 @@ require (
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
golang.org/x/net v0.31.0 // indirect
golang.org/x/sys v0.27.0 // indirect
golang.org/x/text v0.20.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20241007155032-5fefd90f89a9 // indirect
google.golang.org/grpc v1.67.1 // indirect
google.golang.org/grpc v1.68.1 // indirect
google.golang.org/protobuf v1.35.2 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)

replace google.golang.org/genproto => google.golang.org/genproto v0.0.0-20240701130421-f6361c86f094

replace github.com/open-telemetry/opentelemetry-collector-contrib/internal/sharedcomponent => ../../internal/sharedcomponent

replace github.com/open-telemetry/opentelemetry-collector-contrib/internal/coreinternal => ../../internal/coreinternal

replace github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatautil => ../../pkg/pdatautil

replace github.com/open-telemetry/opentelemetry-collector-contrib/pkg/pdatatest => ../../pkg/pdatatest

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