azure-sdk-for-java: [BUG] No telemetry exported form a Scala notebook when using AzureMonitorExporterBuilder
Describe the bug
When running a Scala notebook in a Databricks cluster, instrumentation using AzureMonitorExporterBuilder does not produce any output in the App Insights backend.
Exception or Stack Trace No errors.
To Reproduce
- Have a Databricks workspace
- Have an App Insights instance
- Create a smallest compute cluster with default configuration (I used “Personal Compute” policy).
- Install
com.azure:azure-monitor-opentelemetry-exporter:1.0.0-beta.30in the cluster. - Create a Scala notebook
- Run the below code in the notebook (copy in a cell and run)
Code Snippet
val aiConnStr = "..."
import org.apache.logging.log4j.LogManager
import org.apache.logging.log4j.Level
import org.apache.logging.log4j.core.config.builder.api.ConfigurationBuilderFactory
import org.apache.logging.log4j.core.config.Configurator
import io.opentelemetry.instrumentation.log4j.appender.v2_17.OpenTelemetryAppender
import io.opentelemetry.api.common.Attributes
import io.opentelemetry.api.common.AttributeKey
import io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdk
import com.azure.monitor.opentelemetry.exporter.AzureMonitorExporter
val configBuilder = ConfigurationBuilderFactory.newConfigurationBuilder()
val configuration = configBuilder
.add(
configBuilder
.newAppender("Console", "CONSOLE")
)
.add(
configBuilder
.newAppender("Otel", "OpenTelemetry")
)
.add(
configBuilder
.newRootLogger(Level.INFO)
.add(configBuilder.newAppenderRef("Console"))
.add(configBuilder.newAppenderRef("Otel"))
)
.build(false)
Configurator.initialize(configuration)
val sdkBuilder = AutoConfiguredOpenTelemetrySdk.builder()
AzureMonitorExporter.customize(sdkBuilder, aiConnStr)
val openTelemetry = sdkBuilder.build().getOpenTelemetrySdk()
OpenTelemetryAppender.install(openTelemetry)
println("Configured")
val logger = LogManager.getLogger()
logger.info("ScalaEA Log outside span")
println("log sent")
val attributes = Attributes.of[java.lang.String, java.lang.Long](
AttributeKey.stringKey("foo"), "bar",
AttributeKey.longKey("code"), 42L
)
val tracer = openTelemetry.getTracer("my-notebook")
val span = tracer.spanBuilder("My-span-ScalaEA").startSpan()
val scope = span.makeCurrent()
try {
span.addEvent("ScalaEA span event", attributes)
logger.info("ScalaEA Log from span")
Thread.sleep(1000L)
}
finally {
scope.close()
span.end()
}
println("trace sent")
val meter = openTelemetry.getMeter("my-notebook")
val gauge = meter.gaugeBuilder("my-gauge-ScalaEA").build()
gauge.set(111, attributes)
println("metric sent")
openTelemetry.shutdown()
println("Done")
~Important: run the configuration code (till sdkBuilder.build().getOpenTelemetrySdk()) only once (see #41859). If you ran it and got ConfigurationException, restart the compute cluster (Run -> Restart compute resource).~ – fixed in version 1.0.0-beta.29.
The above code as a gist: https://gist.github.com/greatvovan/a2148bccf2c0e0c2305e8a35e0779dc3
Alternative (with manual configuration): https://gist.github.com/greatvovan/5e9e3d8ecaf4e210ade619c5b55455b3
Expected behavior
3 entries in traces table (2 logs, 1 event), 1 entry in customMetrics, 1 entry in dependencies table (span) created in App Insights
Screenshots N/A
Additional context
- Sending telemetry from a Python notebook on the same cluster works fine, which I am guessing enough to rule out a connectivity problem.
- The same code works fine as a standalone Scala program and produces the expected telemetry.
- Documentation used.
- Based on examples.
Setup (please complete the following information):
- OS: Linux-like (unknown)
- IDE: Databricks Notebook
- Library/Libraries: com.azure:azure-monitor-opentelemetry-exporter:1.0.0-beta.30
- Java version: 1.8.0.412
- App Server/Environment: Databricks runtime 15.4 LTS ML (no GPU)
- Frameworks: No
Information Checklist Kindly make sure that you have added all the following information above and checkoff the required fields otherwise we will treat the issuer as an incomplete report
- Bug Description Added
- Repro Steps Added
- Setup information Added
EDIT: Updated the gists to look more like linear Scala programs. EDIT: Updated the code for version 1.0.0-beta.29 (the gists remain for version 28). EDIT: Bumped version to 1.0.0-beta.30.
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 17 (9 by maintainers)
so if this was a maven project, here’s what I would do:
I didn’t try it in Databricks, but it looks like they give you an option to add exclusions:
so I’d try to install
com.azure:azure-monitor-opentelemetry-exporterwith exclusion ~com.azure:azure-core-http-okhttp~com.azure:azure-core-http-nettyand then also install
com.azure:azure-core-http-okhttpyeah, open your cluster and go to the Driver logs tab, then look at the log4j logs
btw, not sure if this might be interesting / relevant to follow: https://github.com/open-telemetry/opentelemetry-java-instrumentation/issues/12468
hi @greatvovan! I was able to reproduce your findings
and it took me a while, but I finally found where the logs go in azure databricks 😅
and saw this:
so it looks like databricks is bringing their own (older) version of netty which is conflicting with the version used by Azure SDK libraries
the good news is that Azure SDK libraries support alternate http client implementations, so I think you should be able to exclude
com.azure:azure-core-http-netty(which is a transitive dependency ofcom.azure:azure-monitor-opentelemetry-exporter) and includecom.azure:azure-core-http-okhttpinstead@lmolkova I tried
openTelemetry.shutdown()as well asThread.sleep(...)at the end, but it did not change anything.