Skip to content

Commit

Permalink
Add Attribute containing middleware version
Browse files Browse the repository at this point in the history
  • Loading branch information
NthPortal committed Dec 12, 2024
1 parent 3b029ea commit d675146
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ import java.util.Locale
/** Methods for creating appropriate `Attribute`s from typed HTTP objects. */
object TypedAttributes {
private[this] lazy val knownMethods: Set[Method] = Method.all.toSet
private[middleware] val middlewareVersion: Attribute[String] =
Attribute(
"org.http4s.otel4s.middleware.version",
org.http4s.otel4s.middleware.BuildInfo.version,
)

/** The http.request.method `Attribute` with the special value _OTHER */
val httpRequestMethodOther: Attribute[String] =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,21 @@ trait AttributeProvider { self =>
that.responseAttributes(response, headersAllowedAsAttributes)
}
}

object AttributeProvider {

/** Provides an `Attribute` containing this middleware's version. */
val middlewareVersion: AttributeProvider =
new AttributeProvider {
def requestAttributes[F[_]](
request: Request[F],
urlTemplateClassifier: UriTemplateClassifier,
urlRedactor: UriRedactor,
headersAllowedAsAttributes: Set[AuthScheme],
): Attributes = Attributes(TypedAttributes.middlewareVersion)
def responseAttributes[F[_]](
response: Response[F],
headersAllowedAsAttributes: Set[AuthScheme],
): Attributes = Attributes.empty
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,6 @@ trait SpanDataProvider extends AttributeProvider { self =>

object SpanDataProvider {

/** The default provider, which follows OpenTelemetry semantic conventions. */
def default: SpanDataProvider = openTelemetry

/** A `SpanAndAttributeProvider` following OpenTelemetry semantic conventions. */
val openTelemetry: SpanDataProvider = {
final case class Data(httpRequestMethod: Attribute[String]) {
Expand Down Expand Up @@ -240,4 +237,9 @@ object SpanDataProvider {
}
}
}

/** The default provider, which follows OpenTelemetry semantic conventions
* and includes this middleware's version.
*/
val default: SpanDataProvider = openTelemetry.and(AttributeProvider.middlewareVersion)
}
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,21 @@ trait AttributeProvider { self =>
that.responseAttributes(response, headersAllowedAsAttributes)
}
}

object AttributeProvider {

/** Provides an `Attribute` containing this middleware's version. */
val middlewareVersion: AttributeProvider =
new AttributeProvider {
def requestAttributes[F[_]](
request: Request[F],
routeClassifier: RouteClassifier,
redactor: PathAndQueryRedactor,
headersAllowedAsAttributes: Set[AuthScheme],
): Attributes = Attributes(TypedAttributes.middlewareVersion)
def responseAttributes[F[_]](
response: Response[F],
headersAllowedAsAttributes: Set[AuthScheme],
): Attributes = Attributes.empty
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,6 @@ trait SpanDataProvider extends AttributeProvider { self =>

object SpanDataProvider {

/** The default provider, which follows OpenTelemetry semantic conventions. */
def default: SpanDataProvider = openTelemetry

/** A `SpanAndAttributeProvider` following OpenTelemetry semantic conventions. */
val openTelemetry: SpanDataProvider = {
final case class Data(
Expand Down Expand Up @@ -255,4 +252,9 @@ object SpanDataProvider {
}
}
}

/** The default provider, which follows OpenTelemetry semantic conventions
* and includes this middleware's version.
*/
val default: SpanDataProvider = openTelemetry.and(AttributeProvider.middlewareVersion)
}

0 comments on commit d675146

Please sign in to comment.