Skip to content

Commit

Permalink
fix(telemetry): do not create custom events if level is off (#5165)
Browse files Browse the repository at this point in the history
Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com>
  • Loading branch information
bnjjj authored and Geal committed Jun 10, 2024
1 parent 882eb17 commit 84a12fe
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 31 deletions.
26 changes: 26 additions & 0 deletions .changesets/fix_bnjjj_fix_custom_events_off.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
### Do not create custom events in telemetry if level is off ([PR #5165](https://github.com/apollographql/router/pull/5165))

Don't create custom events and attributes if you set the level to `off`

example of configuration:

```yaml
telemetry:
instrumentation:
events:
router:
# Standard events
request: info
response: info
error: info

# Custom events
my.disabled_request_event:
message: "my event message"
level: off # Disabled because we set the level to off
on: request
attributes:
http.request.body.size: true
```

By [@bnjjj](https://github.com/bnjjj) in https://github.com/apollographql/router/pull/5165
63 changes: 36 additions & 27 deletions apollo-router/src/plugins/telemetry/config_new/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,18 @@ impl Events {
.router
.custom
.iter()
.map(|(event_name, event_cfg)| CustomEvent {
inner: Mutex::new(CustomEventInner {
name: event_name.clone(),
level: event_cfg.level,
event_on: event_cfg.on,
message: event_cfg.message.clone(),
selectors: event_cfg.attributes.clone().into(),
condition: event_cfg.condition.clone(),
attributes: Vec::new(),
.filter_map(|(event_name, event_cfg)| match &event_cfg.level {
EventLevel::Off => None,
_ => Some(CustomEvent {
inner: Mutex::new(CustomEventInner {
name: event_name.clone(),
level: event_cfg.level,
event_on: event_cfg.on,
message: event_cfg.message.clone(),
selectors: event_cfg.attributes.clone().into(),
condition: event_cfg.condition.clone(),
attributes: Vec::new(),
}),
}),
})
.collect();
Expand All @@ -72,15 +75,18 @@ impl Events {
.supergraph
.custom
.iter()
.map(|(event_name, event_cfg)| CustomEvent {
inner: Mutex::new(CustomEventInner {
name: event_name.clone(),
level: event_cfg.level,
event_on: event_cfg.on,
message: event_cfg.message.clone(),
selectors: event_cfg.attributes.clone().into(),
condition: event_cfg.condition.clone(),
attributes: Vec::new(),
.filter_map(|(event_name, event_cfg)| match &event_cfg.level {
EventLevel::Off => None,
_ => Some(CustomEvent {
inner: Mutex::new(CustomEventInner {
name: event_name.clone(),
level: event_cfg.level,
event_on: event_cfg.on,
message: event_cfg.message.clone(),
selectors: event_cfg.attributes.clone().into(),
condition: event_cfg.condition.clone(),
attributes: Vec::new(),
}),
}),
})
.collect();
Expand All @@ -98,15 +104,18 @@ impl Events {
.subgraph
.custom
.iter()
.map(|(event_name, event_cfg)| CustomEvent {
inner: Mutex::new(CustomEventInner {
name: event_name.clone(),
level: event_cfg.level,
event_on: event_cfg.on,
message: event_cfg.message.clone(),
selectors: event_cfg.attributes.clone().into(),
condition: event_cfg.condition.clone(),
attributes: Vec::new(),
.filter_map(|(event_name, event_cfg)| match &event_cfg.level {
EventLevel::Off => None,
_ => Some(CustomEvent {
inner: Mutex::new(CustomEventInner {
name: event_name.clone(),
level: event_cfg.level,
event_on: event_cfg.on,
message: event_cfg.message.clone(),
selectors: event_cfg.attributes.clone().into(),
condition: event_cfg.condition.clone(),
attributes: Vec::new(),
}),
}),
})
.collect();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,17 @@ telemetry:
error: info

# Custom events
my.disabled_request_event:
message: "my event message"
level: off
on: request
attributes:
http.request.body.size: true
# Only log when the x-log-request header is `log`
condition:
eq:
- "log"
- request_header: "x-log-request"
my.request_event:
message: "my event message"
level: info
Expand Down Expand Up @@ -40,6 +51,15 @@ telemetry:
error: info

# Custom events
my.disabled_request.event:
message: "my event message"
level: off
on: request
# Only log when the x-log-request header is `log`
condition:
eq:
- "log"
- request_header: "x-log-request"
my.request.event:
message: "my event message"
level: info
Expand All @@ -64,6 +84,10 @@ telemetry:
error: error

# Custom events
my.disabled_request.event:
message: "my event message"
level: off
on: request
my.request.event:
message: "my event message"
level: info
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,15 @@ telemetry:

### `level`

Custom events have a level, `trace`, `debug`, `info`, `warn` or `error`. The level determines the severity of the event.
Custom events have a level, `trace`, `debug`, `info`, `warn`, `error` or `off` (if you want to disable this event). The level determines the severity of the event.

To set the level:
```yaml title="future.router.yaml"
telemetry:
events:
router:
acme.event:
level: info # trace, debug, info, warn, error
level: info # trace, debug, info, warn, error, off
# ...
```

Expand Down Expand Up @@ -195,8 +195,8 @@ telemetry:
| Option | Values | Default | Description |
|--------------------|------------------------------------------------------------------------------|---------|-------------------------------------------------------------|
| `<attribute-name>` | | | The name of the custom attribute. |
| `attributes` | [standard attributes](./standard-attributes) or [selectors](./selectors) | | The attributes of the custom log event. |
| `condition` | [conditions](./conditions) | | The condition that must be met for the event to be emitted. |
| `attributes` | [standard attributes](./standard-attributes) or [selectors](./selectors) | | The attributes of the custom log event. |
| `condition` | [conditions](./conditions) | | The condition that must be met for the event to be emitted. |
| `error` | `trace`\|`info`\|`warn`\|`error`\| `off` | `off` | The level of the error log event. |
| `level` | `trace`\|`info`\|`warn`\|`error`\| `off` | `off` | The level of the custom log event. |
| `message` | | | The message of the custom log event. |
Expand Down

0 comments on commit 84a12fe

Please sign in to comment.