Skip to content

Commit b1ef95f

Browse files
committed
build
1 parent 5d087e3 commit b1ef95f

File tree

3 files changed

+44
-16
lines changed

3 files changed

+44
-16
lines changed

plugins/core/jetbrains-community/src/software/aws/toolkits/jetbrains/services/telemetry/otel/OTelService.kt

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,19 @@ package software.aws.toolkits.jetbrains.services.telemetry.otel
66

77
import com.intellij.openapi.Disposable
88
import com.intellij.openapi.components.Service
9+
import com.intellij.openapi.components.service
910
import com.intellij.openapi.diagnostic.thisLogger
10-
import com.intellij.platform.diagnostic.telemetry.impl.OpenTelemetryConfigurator
11+
import com.intellij.openapi.util.SystemInfoRt
1112
import com.intellij.platform.util.http.ContentType
1213
import com.intellij.platform.util.http.httpPost
14+
import io.opentelemetry.api.common.AttributeKey
15+
import io.opentelemetry.api.common.Attributes
1316
import io.opentelemetry.api.trace.propagation.W3CTraceContextPropagator
1417
import io.opentelemetry.context.Context
1518
import io.opentelemetry.context.propagation.ContextPropagators
1619
import io.opentelemetry.exporter.internal.otlp.traces.TraceRequestMarshaler
1720
import io.opentelemetry.sdk.OpenTelemetrySdk
21+
import io.opentelemetry.sdk.resources.Resource
1822
import io.opentelemetry.sdk.trace.ReadWriteSpan
1923
import io.opentelemetry.sdk.trace.ReadableSpan
2024
import io.opentelemetry.sdk.trace.SdkTracerProvider
@@ -127,25 +131,33 @@ private object StdoutSpanProcessor : SpanProcessor {
127131
@Service
128132
class OTelService : Disposable {
129133
private val sdkDelegate = lazy {
130-
val configurator = OpenTelemetryConfigurator(
131-
sdkBuilder = OpenTelemetrySdk.builder(),
132-
)
133-
134-
configurator.getConfiguredSdkBuilder()
134+
OpenTelemetrySdk.builder()
135135
.setTracerProvider(
136136
SdkTracerProvider.builder()
137137
.addSpanProcessor(StdoutSpanProcessor)
138-
.setResource(configurator.resource)
138+
.setResource(
139+
Resource.create(
140+
Attributes.builder()
141+
.put(AttributeKey.stringKey("os.type"), SystemInfoRt.OS_NAME)
142+
.put(AttributeKey.stringKey("os.version"), SystemInfoRt.OS_VERSION)
143+
.put(AttributeKey.stringKey("host.arch"), System.getProperty("os.arch"))
144+
.build()
145+
)
146+
)
139147
.build()
140148
)
141149
.setPropagators(ContextPropagators.create(W3CTraceContextPropagator.getInstance()))
142150
.build()
143151
}
144-
val sdk: OpenTelemetrySdk by sdkDelegate
152+
internal val sdk: OpenTelemetrySdk by sdkDelegate
145153

146154
override fun dispose() {
147155
if (sdkDelegate.isInitialized()) {
148156
sdk.close()
149157
}
150158
}
159+
160+
companion object {
161+
fun getSdk() = service<OTelService>().sdk
162+
}
151163
}

plugins/core/jetbrains-community/src/software/aws/toolkits/jetbrains/services/telemetry/otel/OtelBase.kt

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
package software.aws.toolkits.jetbrains.services.telemetry.otel
55

6-
import com.intellij.platform.diagnostic.telemetry.helpers.useWithoutActiveScope
6+
import com.intellij.platform.diagnostic.telemetry.helpers.use as ijUse
77
import io.opentelemetry.api.common.AttributeKey
88
import io.opentelemetry.api.common.Attributes
99
import io.opentelemetry.api.trace.Span
@@ -17,7 +17,6 @@ import software.amazon.awssdk.services.toolkittelemetry.model.AWSProduct
1717
import software.aws.toolkits.jetbrains.services.telemetry.PluginResolver
1818
import java.time.Instant
1919
import java.util.concurrent.TimeUnit
20-
import kotlin.use
2120

2221
val AWS_PRODUCT_CONTEXT_KEY = ContextKey.named<AWSProduct>("pluginDescriptor")
2322
private val PLUGIN_ATTRIBUTE_KEY = AttributeKey.stringKey("plugin")
@@ -33,10 +32,8 @@ abstract class AbstractSpanBuilder<Builder : AbstractSpanBuilder<Builder, Span>,
3332
* @inheritdoc
3433
*/
3534
inline fun<T> use(operation: (Span) -> T): T =
36-
startSpan().useWithoutActiveScope { span ->
37-
(span as Span).makeCurrent().use {
38-
operation(span)
39-
}
35+
startSpan().ijUse { span ->
36+
operation(span as Span)
4037
}
4138

4239
protected var parent: Context? = null
@@ -124,9 +121,10 @@ abstract class AbstractSpanBuilder<Builder : AbstractSpanBuilder<Builder, Span>,
124121

125122
val contextValue = parent.get(AWS_PRODUCT_CONTEXT_KEY)
126123
if (contextValue == null) {
127-
val s = Span.fromContextOrNull(parent)
124+
// FIX_WHEN_MIN_IS_243: Kotlin compiler can't figure out difference between class/type parameter until 2.x
125+
val s = io.opentelemetry.api.trace.Span.fromContextOrNull(parent)
128126
if (s is AbstractBaseSpan) {
129-
setParent(s.context.with(Span.fromContext(parent)))
127+
setParent(s.context.with(io.opentelemetry.api.trace.Span.fromContext(parent)))
130128
} else {
131129
setParent(parent.with(AWS_PRODUCT_CONTEXT_KEY, resolvePluginName()))
132130
}
@@ -144,6 +142,16 @@ abstract class AbstractSpanBuilder<Builder : AbstractSpanBuilder<Builder, Span>,
144142
}
145143

146144
abstract class AbstractBaseSpan(internal val context: Context, private val delegate: Span) : Span by delegate {
145+
/**
146+
* Same as [com.intellij.platform.diagnostic.telemetry.helpers.use] except downcasts to specific subclass of [BaseSpan]
147+
*
148+
* @inheritdoc
149+
*/
150+
inline fun<T> use(operation: (Span) -> T): T =
151+
ijUse { span ->
152+
operation(span as Span)
153+
}
154+
147155
fun metadata(key: String, value: String) = setAttribute(key, value)
148156

149157
override fun makeCurrent(): Scope =

plugins/core/jetbrains-community/tst/software/aws/toolkits/jetbrains/core/credentials/sso/SsoCredentialProviderTest.kt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
package software.aws.toolkits.jetbrains.core.credentials.sso
55

6+
import com.intellij.openapi.application.ApplicationManager
67
import com.intellij.testFramework.ApplicationRule
78
import org.assertj.core.api.Assertions.assertThat
89
import org.assertj.core.api.Assertions.assertThatThrownBy
@@ -95,6 +96,13 @@ class SsoCredentialProviderTest {
9596
verify(ssoAccessTokenProvider).invalidate()
9697
}
9798

99+
@Test
100+
fun aaaaa() {
101+
ApplicationManager.getApplication().executeOnPooledThread {
102+
println(Thread.currentThread().getContextClassLoader())
103+
}.get()
104+
}
105+
98106
private fun createSsoResponse(expirationTime: Instant) {
99107
ssoClient.stub {
100108
on(

0 commit comments

Comments
 (0)