Skip to content

Commit

Permalink
[exporter/coralogix] feat: allow setting application name from custom…
Browse files Browse the repository at this point in the history
… resource attributes (open-telemetry#33218)

**Description:** 

allow setting application name from cx.application.name and
cx.subsystem.name attributes. To support simplified use case, such as:

```yaml
receivers:
  filelog/nginx:
    include:
      - '/tmp/tmp.log'
    include_file_path: true
    include_file_name: false
    start_at: end
    resource: 
      cx.subsystem.name: nginx
  filelog/access-log:
    include:
      - '/tmp/access.log'
    include_file_path: true
    include_file_name: false
    resource: 
      cx.subsystem.name: access-log
exporters:
  coralogix:
    domain: 'coralogix.com'
    private_key: "XXX"
    application_name: 'app_name'
    timeout: 30s
service:
  pipelines:
    logs:
      receivers: [filelog/nginx, filelog/access-log]
      exporters: [coralogix]
```

**Link to tracking Issue:** <Issue number if applicable>

open-telemetry#33217

**Testing:** <Describe what testing was performed and which tests were
added.>
- unit tests
- manually tested

**Documentation:** <Describe the documentation added.>

- updated docs

---------

Co-authored-by: Pablo Baeyens <[email protected]>
  • Loading branch information
povilasv and mx-psi authored Jun 5, 2024
1 parent 9e4a906 commit b0e5883
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 3 deletions.
27 changes: 27 additions & 0 deletions .chloggen/coralogix-exporter.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: coralogixexporter

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: "Allow setting application name from `cx.application.name` and `cx.subsystem.name` resource attributes"

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

# (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: []
44 changes: 41 additions & 3 deletions exporter/coralogixexporter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ exporters:

### Exporting to multiple teams based on attributes
You can export the signals based on your business logic (attributes) to different Coralogix teams. To achieve this, you'll need to use the [`filter`](https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/processor/filterprocessor/README.md) processor and setup one pipeline per team. You can setup your `filter` processors as following (example with metrics):
```
```yaml
processors:
filter/teamA:
metrics:
Expand All @@ -246,7 +246,7 @@ processors:
This configuration ensures separate processor per each team. Any data points without an attribute for a particular team will be dropped from exporting.

Secondly, set up an individual exporter per each team:
```
```yaml
exporters:
coralogix/teamA:
metrics:
Expand All @@ -263,7 +263,7 @@ exporters:
```

Finally, join each processor and exporter (and any other components you wish) in the pipelines. Here is an example with a Prometheus receiver:
```
```yaml
service:
pipelines:
metrics/1:
Expand All @@ -276,6 +276,44 @@ service:
exporters: [coralogix/teamB]
```

### Custom application and subsystem name

You can pass custom application and subsystem name via the following resource attributes:

- `cx.subsystem.name`
- `cx.application.name`
For example:

```yaml
receivers:
filelog/nginx:
include:
- '/tmp/tmp.log'
include_file_path: true
include_file_name: false
start_at: end
resource:
cx.subsystem.name: nginx
filelog/access-log:
include:
- '/tmp/access.log'
include_file_path: true
include_file_name: false
resource:
cx.subsystem.name: access-log
exporters:
coralogix:
domain: 'coralogix.com'
private_key: "XXX"
application_name: 'app_name'
timeout: 30s
service:
pipelines:
logs:
receivers: [filelog/nginx, filelog/access-log]
exporters: [coralogix]
```

### Need help?

Our world-class customer success team is available 24/7 to walk you through the setup for this exporter and answer any questions that may come up.
Expand Down
12 changes: 12 additions & 0 deletions exporter/coralogixexporter/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,18 @@ func (c *Config) getMetadataFromResource(res pcommon.Resource) (appName, subsyst
subsystem = c.SubSystem
}

if appName == "" {
attr, ok := res.Attributes().Get(cxAppNameAttrName)
if ok && attr.AsString() != "" {
appName = attr.AsString()
}
}
if subsystem == "" {
attr, ok := res.Attributes().Get(cxSubsystemNameAttrName)
if ok && attr.AsString() != "" {
subsystem = attr.AsString()
}
}
return appName, subsystem
}

Expand Down
8 changes: 8 additions & 0 deletions exporter/coralogixexporter/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,10 @@ func TestGetMetadataFromResource(t *testing.T) {
r2.Attributes().PutStr("k8s.node.name", "node-test")
r2.Attributes().PutStr("k8s.namespace.name", "namespace-test")

r3 := pcommon.NewResource()
r3.Attributes().PutStr("cx.application.name", "application")
r3.Attributes().PutStr("cx.subsystem.name", "subsystem")

c := &Config{
AppNameAttributes: []string{"k8s.container.name", "k8s.deployment.name", "k8s.node.name"},
SubSystemAttributes: []string{"k8s.namespace.name", "k8s.node.name"},
Expand All @@ -305,4 +309,8 @@ func TestGetMetadataFromResource(t *testing.T) {
appName, subSystemName = c.getMetadataFromResource(r2)
assert.Equal(t, "node-test", appName)
assert.Equal(t, "namespace-test", subSystemName)

appName, subSystemName = c.getMetadataFromResource(r3)
assert.Equal(t, "application", appName)
assert.Equal(t, "subsystem", subSystemName)
}

0 comments on commit b0e5883

Please sign in to comment.