apple / apple/swift-statsd-client
Support other formats for metric dimensions
- Dominant language
- Swift
- Stars
- 71
- Forks
- 23
- Avg merge
- 5d 4h
- Merged PRs (30d)
- 2
Description
At present, the use of metrics dimensions results in some metrics being emitted in an unexpected way:
```swift
Timer(label: "my_event", dimensions: [("foo", "bar")]).recordNanoseconds(someDuration)
```
will emit a packet roughly like
```
my_event.foo.bar:123.45|ms
```
However, using the tag format for dimensions would be more appropriate in many applications:
```
my_event:123.45|ms#foo:bar
```
Unfortunately, there's not a standard syntax for tags (see https://github.com/statsd/statsd/issues/619), but I think this could be addressed by having an optional init parameter to specify the format:
```swift
enum DimensionFormat {
case datadog
case influxdb
case inline
// ..
}
class StatsdClient: MetricsFactory {
public init(eventLoopGroupProvider: EventLoopGroupProvider = .createNew, host: String, port: Int, format: DimensionFormat = .inline) throws {
// ...
}
// ...
}
// User initialization code
let statsdClient = try StatsdClient(host: statsdHost, port: statsdPort, format: .datadog)
MetricsSystem.bootstrap(statsdClient)
```
It may be preferable to avoid specific vendor names in the enum cases to avoid any sort of endorsement, but I'm confident that could be addressed.
Thoughts?
Contributor guide
No contributing guide indexed for this repository
Research direction
Start with the StatsdClient initializer and the current dimension serialization used by Timer.recordNanoseconds. Resolve the supported DimensionFormat cases and their encoding rules before defining the API; done means the chosen formats emit the expected metric strings and are covered by tests.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- swift
- Domain
- backend, observability-sre
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100