Skip to content

Commit ab0f6a2

Browse files
authored
[receiver/libhoney] New receiver for libhoney (#36706)
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue. Ex. Adding a feature - Explain what this achieves.--> #### Description Creates a new receiver that accepts libhoney traffic as either logs or traces. This PR doesn't do the conversion yet. Just contains configurations and some factory components. <!-- Issue number (e.g. #1234) or full URL to issue, if applicable. --> #### Link to tracking issue #36693
1 parent 5fed928 commit ab0f6a2

19 files changed

+812
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Use this changelog template to create an entry for release notes.
2+
3+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
4+
change_type: new_component
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
7+
component: libhoneyreceiver
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: Introduce the scaffolding of a new component, libhoneyreceiver
11+
12+
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
13+
issues: [36693]
14+
15+
# (Optional) One or more lines of additional information to render under the primary note.
16+
# These lines will be padded with 2 spaces and then inserted directly into the document.
17+
# Use pipe (|) for multiline entries.
18+
subtext:
19+
20+
# If your change doesn't affect end users or the exported elements of any package,
21+
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
22+
# Optional: The change log or logs in which this entry should be included.
23+
# e.g. '[user]' or '[user, api]'
24+
# Include 'user' if the change is relevant to end users.
25+
# Include 'api' if there is a change to a library API.
26+
# Default: '[user]'
27+
change_logs: []

.github/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ receiver/k8sobjectsreceiver/ @open-telemetry/collector-cont
244244
receiver/kafkametricsreceiver/ @open-telemetry/collector-contrib-approvers @dmitryax
245245
receiver/kafkareceiver/ @open-telemetry/collector-contrib-approvers @pavolloffay @MovieStoreGuy
246246
receiver/kubeletstatsreceiver/ @open-telemetry/collector-contrib-approvers @dmitryax @TylerHelmuth @ChrsMark
247+
receiver/libhoneyreceiver/ @open-telemetry/collector-contrib-approvers @TylerHelmuth
247248
receiver/lokireceiver/ @open-telemetry/collector-contrib-approvers @mar4uk
248249
receiver/memcachedreceiver/ @open-telemetry/collector-contrib-approvers @djaglowski
249250
receiver/mongodbatlasreceiver/ @open-telemetry/collector-contrib-approvers @schmikei

.github/ISSUE_TEMPLATE/bug_report.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ body:
241241
- receiver/kafka
242242
- receiver/kafkametrics
243243
- receiver/kubeletstats
244+
- receiver/libhoney
244245
- receiver/loki
245246
- receiver/memcached
246247
- receiver/mongodb

.github/ISSUE_TEMPLATE/feature_request.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ body:
235235
- receiver/kafka
236236
- receiver/kafkametrics
237237
- receiver/kubeletstats
238+
- receiver/libhoney
238239
- receiver/loki
239240
- receiver/memcached
240241
- receiver/mongodb

.github/ISSUE_TEMPLATE/other.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ body:
235235
- receiver/kafka
236236
- receiver/kafkametrics
237237
- receiver/kubeletstats
238+
- receiver/libhoney
238239
- receiver/loki
239240
- receiver/memcached
240241
- receiver/mongodb

.github/ISSUE_TEMPLATE/unmaintained.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,7 @@ body:
240240
- receiver/kafka
241241
- receiver/kafkametrics
242242
- receiver/kubeletstats
243+
- receiver/libhoney
243244
- receiver/loki
244245
- receiver/memcached
245246
- receiver/mongodb

receiver/libhoneyreceiver/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
include ../../Makefile.Common
2+

receiver/libhoneyreceiver/README.md

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Libhoney Receiver
2+
<!-- status autogenerated section -->
3+
| Status | |
4+
| ------------- |-----------|
5+
| Stability | [development]: traces, logs |
6+
| Distributions | [] |
7+
| Issues | [![Open issues](https://img.shields.io/github/issues-search/open-telemetry/opentelemetry-collector-contrib?query=is%3Aissue%20is%3Aopen%20label%3Areceiver%2Flibhoney%20&label=open&color=orange&logo=opentelemetry)](https://github.com/open-telemetry/opentelemetry-collector-contrib/issues?q=is%3Aopen+is%3Aissue+label%3Areceiver%2Flibhoney) [![Closed issues](https://img.shields.io/github/issues-search/open-telemetry/opentelemetry-collector-contrib?query=is%3Aissue%20is%3Aclosed%20label%3Areceiver%2Flibhoney%20&label=closed&color=blue&logo=opentelemetry)](https://github.com/open-telemetry/opentelemetry-collector-contrib/issues?q=is%3Aclosed+is%3Aissue+label%3Areceiver%2Flibhoney) |
8+
| [Code Owners](https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/CONTRIBUTING.md#becoming-a-code-owner) | [@TylerHelmuth](https://www.github.com/TylerHelmuth) |
9+
10+
[development]: https://github.com/open-telemetry/opentelemetry-collector/blob/main/docs/component-stability.md#development
11+
<!-- end autogenerated section -->
12+
13+
### The purpose and use-cases of the new component
14+
15+
The Libhoney receiver will accept data for either Trace or Logs signals that are emitted from applications that were
16+
instrumented using [Libhoney](https://docs.honeycomb.io/send-data/logs/structured/libhoney/) libraries.
17+
18+
## Configuration
19+
20+
The configuration has 2 parts, One is the HTTP receiver configuration and the rest is about mapping attributes from the
21+
freeform libhoney format into the more structured OpenTelemetry objects.
22+
23+
### Example configuration for the component
24+
25+
The following settings are required:
26+
27+
- `http`
28+
- `endpoint` must set an endpoint. Defaults to `127.0.0.1:8080`
29+
- `resources`: if the `service.name` field is different, map it here.
30+
- `scopes`: to get the `library.name` and `library.version` set in the scope section, set them here.
31+
- `attributes`: if the other trace-related data have different keys, map them here, defaults are otlp-like field names.
32+
33+
The following setting is required for refinery traffic since:
34+
35+
- `auth_api`: should be set to `https://api.honeycomb.io` or a proxy that forwards to that host.
36+
Some libhoney software checks `/1/auth` to get environment names so it needs to be passed through.
37+
38+
39+
```yaml
40+
libhoney:
41+
http:
42+
endpoint: 0.0.0.0:8088
43+
traces_url_paths:
44+
- "/1/events"
45+
- "/1/batch"
46+
include_metadata: true
47+
auth_api: https://api.honeycomb.io
48+
resources:
49+
service_name: service_name
50+
scopes:
51+
library_name: library.name
52+
library_version: library.version
53+
attributes:
54+
trace_id: trace_id
55+
parent_id: parent_id
56+
span_id: span_id
57+
name: name
58+
error: error
59+
spankind: span.kind
60+
durationFields:
61+
- duration_ms
62+
```
63+
64+
### Telemetry data types supported
65+
66+
It will subscribe to the Traces and Logs signals but accept traffic destined for either pipeline using one http receiver
67+
component. Libhoney doesnot differentiate between the two so the receiver will identify which pipeline to deliver the
68+
spans or log records to.
69+
70+
No support for metrics since they'd look just like logs.

receiver/libhoneyreceiver/config.go

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
// Copyright The OpenTelemetry Authors
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
package libhoneyreceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/libhoneyreceiver"
5+
6+
import (
7+
"errors"
8+
"fmt"
9+
"net/url"
10+
"path"
11+
12+
"go.opentelemetry.io/collector/config/confighttp"
13+
"go.opentelemetry.io/collector/confmap"
14+
)
15+
16+
// Config represents the receiver config settings within the collector's config.yaml
17+
type Config struct {
18+
HTTP *HTTPConfig `mapstructure:"http"`
19+
AuthAPI string `mapstructure:"auth_api"`
20+
Wrapper string `mapstructure:"wrapper"`
21+
Resources ResourcesConfig `mapstructure:"resources"`
22+
Scopes ScopesConfig `mapstructure:"scopes"`
23+
Attributes AttributesConfig `mapstructure:"attributes"`
24+
}
25+
26+
type HTTPConfig struct {
27+
*confighttp.ServerConfig `mapstructure:",squash"`
28+
29+
// The URL path to receive traces on. If omitted "/" will be used.
30+
TracesURLPaths []string `mapstructure:"traces_url_paths,omitempty"`
31+
}
32+
33+
type ResourcesConfig struct {
34+
ServiceName string `mapstructure:"service_name"`
35+
}
36+
37+
type ScopesConfig struct {
38+
LibraryName string `mapstructure:"library_name"`
39+
LibraryVersion string `mapstructure:"library_version"`
40+
}
41+
42+
type AttributesConfig struct {
43+
TraceID string `mapstructure:"trace_id"`
44+
ParentID string `mapstructure:"parent_id"`
45+
SpanID string `mapstructure:"span_id"`
46+
Name string `mapstructure:"name"`
47+
Error string `mapstructure:"error"`
48+
SpanKind string `mapstructure:"spankind"`
49+
DurationFields []string `mapstructure:"durationFields"`
50+
}
51+
52+
func (cfg *Config) Validate() error {
53+
if cfg.HTTP == nil {
54+
return errors.New("must specify at least one protocol when using the arbitrary JSON receiver")
55+
}
56+
return nil
57+
}
58+
59+
func (cfg *Config) Unmarshal(conf *confmap.Conf) error {
60+
// first load the config normally
61+
err := conf.Unmarshal(cfg)
62+
if err != nil {
63+
return err
64+
}
65+
66+
if !conf.IsSet("http") {
67+
cfg.HTTP = nil
68+
} else {
69+
var err error
70+
71+
for idx := range cfg.HTTP.TracesURLPaths {
72+
if cfg.HTTP.TracesURLPaths[idx], err = sanitizeURLPath(cfg.HTTP.TracesURLPaths[idx]); err != nil {
73+
return err
74+
}
75+
}
76+
}
77+
if cleanURL, err := url.Parse(cfg.AuthAPI); err != nil {
78+
cfg.AuthAPI = cleanURL.String()
79+
} else {
80+
return err
81+
}
82+
83+
return nil
84+
}
85+
86+
func sanitizeURLPath(urlPath string) (string, error) {
87+
u, err := url.Parse(urlPath)
88+
if err != nil {
89+
return "", fmt.Errorf("invalid HTTP URL path set for signal: %w", err)
90+
}
91+
92+
if !path.IsAbs(u.Path) {
93+
u.Path = "/" + u.Path
94+
}
95+
return u.Path, nil
96+
}

receiver/libhoneyreceiver/doc.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// Copyright The OpenTelemetry Authors
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
//go:generate mdatagen metadata.yaml
5+
6+
package libhoneyreceiver // import "github.com/open-telemetry/opentelemetry-collector-contrib/receiver/libhoneyreceiver"

0 commit comments

Comments
 (0)