|
| 1 | +/* |
| 2 | + * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. |
| 3 | + * SPDX-License-Identifier: Apache-2.0 |
| 4 | + */ |
| 5 | + |
| 6 | +package software.amazon.smithy.rustsdk |
| 7 | + |
| 8 | +import software.amazon.smithy.model.shapes.OperationShape |
| 9 | +import software.amazon.smithy.rust.codegen.client.smithy.ClientCodegenContext |
| 10 | +import software.amazon.smithy.rust.codegen.client.smithy.customize.ClientCodegenDecorator |
| 11 | +import software.amazon.smithy.rust.codegen.client.smithy.generators.OperationCustomization |
| 12 | +import software.amazon.smithy.rust.codegen.client.smithy.generators.OperationSection |
| 13 | +import software.amazon.smithy.rust.codegen.core.rustlang.Writable |
| 14 | +import software.amazon.smithy.rust.codegen.core.rustlang.writable |
| 15 | +import software.amazon.smithy.rust.codegen.core.util.dq |
| 16 | + |
| 17 | +/** |
| 18 | + * Adds the AWS SDK specific `rpc.system = "aws-api"` field to the operation's tracing span |
| 19 | + */ |
| 20 | +class SpanDecorator : ClientCodegenDecorator { |
| 21 | + override val name: String = "SpanDecorator" |
| 22 | + override val order: Byte = 0 |
| 23 | + |
| 24 | + override fun operationCustomizations( |
| 25 | + codegenContext: ClientCodegenContext, |
| 26 | + operation: OperationShape, |
| 27 | + baseCustomizations: List<OperationCustomization>, |
| 28 | + ): List<OperationCustomization> { |
| 29 | + return baseCustomizations + |
| 30 | + object : OperationCustomization() { |
| 31 | + private val runtimeConfig = codegenContext.runtimeConfig |
| 32 | + |
| 33 | + override fun section(section: OperationSection): Writable { |
| 34 | + return writable { |
| 35 | + when (section) { |
| 36 | + is OperationSection.AdditionalOperationSpanFields -> { |
| 37 | + section.addField(this, "rpc.system", writable("aws-api".dq())) |
| 38 | + } |
| 39 | + |
| 40 | + else -> {} |
| 41 | + } |
| 42 | + } |
| 43 | + } |
| 44 | + } |
| 45 | + } |
| 46 | +} |
0 commit comments