Hi Ktor Community :pikachu-hi: I’m encountering a...
# ktor
m
Hi Ktor Community pikachu hi I’m encountering an issue where metrics sent to Grafana using Micrometer are being tagged with the HTTP response body of incoming HTTP calls. This is not the desired behavior, as the response body contains potentially sensitive or unnecessary information that should not be included in the metrics. Here’s an outline of the symptoms: • Metrics are being collected and sent successfully, but the tags unexpectedly include the content of the HTTP response body. • This issue occurs specifically for incoming HTTP calls handled by the application. • I suspect the response body might be unintentionally included as a tag due to some interceptor, filter, or configuration related to Micrometer or Ktor itself. I’m using Micrometer for metrics collection and am unsure if this issue is caused by: 1. A misconfiguration in my Micrometer setup. 2. An interceptor or feature in Ktor that is adding the response body as a tag. 3. Something else I might be overlooking. Has anyone experienced a similar issue or could provide insights on how to prevent response bodies from being tagged in metrics? Any suggestions on debugging or configuring this would be greatly appreciated. Config in thread 🧵
Copy code
private fun getStatsdMeterRegistry(): StatsdMeterRegistry {
        val statsdConfig = getMeterConfig()
        val statsdMeterRegistry = StatsdMeterRegistry(statsdConfig, Clock.SYSTEM)
        statsdMeterRegistry.Config()
            .namingConvention { name, _, _ -> "$SERVICE_METRICS_PREFIX.$name" }
            .commonTags(
                listOf(
                    Tag.of("env", Environment.getEnvironment()),
                    Tag.of("service", Config.getAppName()),
                    Tag.of("version", Config.getAppVersion())
                )
            )
        return statsdMeterRegistry
    }

    private fun getMeterConfig(): StatsdConfig {
        return StatsdConfig { path ->
            when (path) {
                "statsd.host" -> HOST
                "statsd.port" -> PORT.toString()
                "statsd.enabled" -> ENABLED.toString()
                "statsd.step" -> STEP
                else -> null
            }
        }
    }
Copy code
fun Application.features() {
install(MicrometerMetrics) {
            registry = KtorMicrometer.getRegistry()
            meterBinders = KtorMicrometer.meterBinders()
            timers { call, throwable ->
                throwable?.apply { tag("exception_message", this.message ?: String.EMPTY) }
                tag("origin", call.request.headers[Headers.ORIGIN] ?: "UNKNOWN")
                tag("platform", call.request.headers[Headers.APP_PLATFORM] ?: "UNKNOWN")
                tag("app_version", call.request.headers[Headers.APP_VERSION] ?: "UNKNOWN")
            }
        }
}
All those labels are part of body response. At some point something is intercepting the api call and is building those tags with underscores
Copy code
val ktorVersion: String by project.extra { "2.3.8" }
val micrometerVersion: String by project.extra { "1.12.3" }


implementation("io.ktor:ktor-server-metrics-micrometer:$ktorVersion")
    implementation("io.micrometer:micrometer-registry-statsd:$micrometerVersion")
@Lucas Milotich ☝️
a
Can you please describe how your problem can be reproduced with the given configuration? Also, can you try using Ktor version 2.3.13?
m
Let me try that ktor version first 🙂
With that configuration and those versions, to reproduce it all you have to do is execute any HTTP request to the application. Incrementing the Ktor version does not resolve the problem
a
I can't resolve some symbols used in your code. Can you please file an issue with a self-contained code snippet attached?