Skip to content

Commit

Permalink
feat: remove opentelemetrySemconv deps (#435)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ahoo-Wang authored Dec 25, 2024
1 parent 3162979 commit 079a93b
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 14 deletions.
1 change: 0 additions & 1 deletion cosec-dependencies/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ dependencies {
api(libs.javaJwt)
api(libs.ip2region)
api(libs.guava)
api(libs.opentelemetrySemconv)
api(libs.swagger)
api(libs.jmhCore)
api(libs.jmhGeneratorAnnprocess)
Expand Down
1 change: 0 additions & 1 deletion cosec-opentelemetry/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
dependencies {
implementation(project(":cosec-core"))
implementation("io.opentelemetry.instrumentation:opentelemetry-instrumentation-api")
implementation("io.opentelemetry:opentelemetry-semconv")
testImplementation("io.projectreactor:reactor-test")
testImplementation("io.opentelemetry:opentelemetry-sdk")
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ package me.ahoo.cosec.opentelemetry

import io.opentelemetry.api.GlobalOpenTelemetry
import io.opentelemetry.api.common.AttributeKey
import io.opentelemetry.api.common.AttributeKey.stringKey
import io.opentelemetry.api.common.AttributesBuilder
import io.opentelemetry.context.Context
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor
import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter
import io.opentelemetry.instrumentation.api.instrumenter.SpanNameExtractor
import io.opentelemetry.semconv.trace.attributes.SemanticAttributes
import me.ahoo.cosec.api.CoSec
import me.ahoo.cosec.api.authorization.AuthorizeResult
import me.ahoo.cosec.api.context.SecurityContext
Expand Down Expand Up @@ -50,16 +50,18 @@ object CoSecSpanNameExtractor : SpanNameExtractor<SecurityContext> {
}

object CoSecAttributesExtractor : AttributesExtractor<SecurityContext, AuthorizeResult> {
private val END_USER_ID_ATTRIBUTE_KEY = stringKey("enduser.id")
private val END_USER_ROLE_ATTRIBUTE_KEY = stringKey("enduser.role")
private const val COSEC_TENANT_ID_KEY = CoSec.COSEC_PREFIX + "tenant_id"
private val COSEC_TENANT_ID_ATTRIBUTE_KEY = AttributeKey.stringKey(COSEC_TENANT_ID_KEY)
private val COSEC_TENANT_ID_ATTRIBUTE_KEY = stringKey(COSEC_TENANT_ID_KEY)

private const val COSEC_POLICY_KEY = CoSec.COSEC_PREFIX + PolicyCapable.POLICY_KEY
private val COSEC_POLICY_ATTRIBUTE_KEY = AttributeKey.stringKey(COSEC_POLICY_KEY)
private val COSEC_POLICY_ATTRIBUTE_KEY = stringKey(COSEC_POLICY_KEY)

private const val COSEC_AUTHORIZE_PREFIX = CoSec.COSEC_PREFIX + "authorize."

private const val COSEC_AUTHORIZATION_POLICY_ID_KEY = COSEC_AUTHORIZE_PREFIX + "policy.id"
private val COSEC_AUTHORIZATION_POLICY_ID_ATTRIBUTE_KEY = AttributeKey.stringKey(COSEC_AUTHORIZATION_POLICY_ID_KEY)
private val COSEC_AUTHORIZATION_POLICY_ID_ATTRIBUTE_KEY = stringKey(COSEC_AUTHORIZATION_POLICY_ID_KEY)

private const val COSEC_AUTHORIZATION_STATEMENT_PREFIX = COSEC_AUTHORIZE_PREFIX + "statement."
private const val COSEC_AUTHORIZATION_STATEMENT_IDX_KEY = COSEC_AUTHORIZATION_STATEMENT_PREFIX + "index"
Expand All @@ -68,17 +70,17 @@ object CoSecAttributesExtractor : AttributesExtractor<SecurityContext, Authorize

private const val COSEC_AUTHORIZATION_STATEMENT_NAME_KEY = COSEC_AUTHORIZATION_STATEMENT_PREFIX + "name"
private val COSEC_AUTHORIZATION_STATEMENT_NAME_ATTRIBUTE_KEY =
AttributeKey.stringKey(COSEC_AUTHORIZATION_STATEMENT_NAME_KEY)
stringKey(COSEC_AUTHORIZATION_STATEMENT_NAME_KEY)

private const val COSEC_AUTHORIZATION_ROLE_ID_KEY = COSEC_AUTHORIZE_PREFIX + "role.id"
private val COSEC_AUTHORIZATION_ROLE_ID_ATTRIBUTE_KEY = AttributeKey.stringKey(COSEC_AUTHORIZATION_ROLE_ID_KEY)
private val COSEC_AUTHORIZATION_ROLE_ID_ATTRIBUTE_KEY = stringKey(COSEC_AUTHORIZATION_ROLE_ID_KEY)

private const val COSEC_AUTHORIZATION_PERMISSION_ID_KEY = COSEC_AUTHORIZE_PREFIX + "permission.id"
private val COSEC_AUTHORIZATION_PERMISSION_ID_ATTRIBUTE_KEY =
AttributeKey.stringKey(COSEC_AUTHORIZATION_PERMISSION_ID_KEY)
stringKey(COSEC_AUTHORIZATION_PERMISSION_ID_KEY)

private const val COSEC_AUTHORIZATION_RESULT_KEY = COSEC_AUTHORIZE_PREFIX + "result"
private val COSEC_AUTHORIZATION_RESULT_ATTRIBUTE_KEY = AttributeKey.stringKey(COSEC_AUTHORIZATION_RESULT_KEY)
private val COSEC_AUTHORIZATION_RESULT_ATTRIBUTE_KEY = stringKey(COSEC_AUTHORIZATION_RESULT_KEY)

private const val SEPARATOR = ","
override fun onStart(attributes: AttributesBuilder, parentContext: Context, request: SecurityContext) = Unit
Expand All @@ -93,9 +95,9 @@ object CoSecAttributesExtractor : AttributesExtractor<SecurityContext, Authorize
val securityContext = request
val principal = securityContext.principal
attributes.put(COSEC_TENANT_ID_ATTRIBUTE_KEY, securityContext.tenant.tenantId)
attributes.put(SemanticAttributes.ENDUSER_ID, principal.id)
attributes.put(END_USER_ID_ATTRIBUTE_KEY, principal.id)
val roleStr = principal.roles.joinToString(SEPARATOR)
attributes.put(SemanticAttributes.ENDUSER_ROLE, roleStr)
attributes.put(END_USER_ROLE_ATTRIBUTE_KEY, roleStr)
val policyStr = principal.policies.joinToString(SEPARATOR)
attributes.put(COSEC_POLICY_ATTRIBUTE_KEY, policyStr)
val verifyContext = securityContext.getVerifyContext()
Expand Down
2 changes: 0 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ springCloud = "2024.0.0"
cosid = "2.10.1"
cocache = "2.6.1"
opentelemetry = "2.11.0"
opentelemetrySemconv = "1.22.0-alpha"
testcontainers = "1.20.4"
guava = "33.4.0-jre"
ognl = "3.4.3"
Expand All @@ -28,7 +27,6 @@ springCloudDependencies = { module = "org.springframework.cloud:spring-cloud-dep
cosidBom = { module = "me.ahoo.cosid:cosid-bom", version.ref = "cosid" }
cocacheBom = { module = "me.ahoo.cocache:cocache-bom", version.ref = "cocache" }
opentelemetryInstrumentationBom = { module = "io.opentelemetry.instrumentation:opentelemetry-instrumentation-bom", version.ref = "opentelemetry" }
opentelemetrySemconv = { module = "io.opentelemetry:opentelemetry-semconv", version.ref = "opentelemetrySemconv" }
testcontainersBom = { module = "org.testcontainers:testcontainers-bom", version.ref = "testcontainers" }
guava = { module = "com.google.guava:guava", version.ref = "guava" }
ognl = { module = "ognl:ognl", version.ref = "ognl" }
Expand Down

0 comments on commit 079a93b

Please sign in to comment.