jenkinsci / opentelemetry-plugin

Monitor and observe Jenkins with OpenTelemetry.
https://plugins.jenkins.io/opentelemetry/
Apache License 2.0
94 stars 47 forks source link

[BUG] Missing properties causing java.lang.NullPointerException #878

Closed fl-max closed 16 hours ago

fl-max commented 3 days ago

Jenkins and plugins versions report

Environment ```text Jenkins: 2.440.3.8 OS: Linux - 5.10.219-208.866.amzn2.x86_64 Java: 11.0.23 - Amazon.com Inc. (OpenJDK 64-Bit Server VM) --- opentelemetry:3.1215.vc9db_a_0b_34c2a_ ```

What Operating System are you using (both controller, and any agents involved in the problem)?

AL2

Reproduction steps

  1. Using CaSC, deploy Controller with the following
    unclassified:
    openTelemetry:
    authentication:
      otlpHeaderAuthentication:
        headerName: "api-key"
        headerValueId: "${otel_credential_id}"
    configurationProperties: |-
      otel.metrics.exporter=otlp
      otel.traces.exporter=otlp
    disabledResourceProviders: "io.opentelemetry.instrumentation.resources.ProcessResourceProvider"
    endpoint: "${otel_endpoint}"
    exportOtelConfigurationAsEnvironmentVariables: true
    exporterIntervalMillis: 60000
    exporterTimeoutMillis: 30000
    ignoredSteps: "dir,echo,isUnix,pwd,properties"
    serviceName: "${CONTROLLER_ENDPOINT}"
    serviceNamespace: "jenkins"
    trustedCertificatesPem: ""
    observabilityBackends:
    - customObservabilityBackend:
        name: "NewRelic"
        metricsVisualizationUrlTemplate: "https://one.newrelic.com/distributed-tracing?account=${newrelic_acct_id}&state=^${traceId}"
        traceVisualisationUrlTemplate: "https://one.newrelic.com/distributed-tracing?account=${newrelic_acct_id}&state=^${traceId}"

Expected Results

Expectation is no errors in logs and Noteworthy active configuration properties & Active resource attributes sections populated with properties.

Actual Results

We see a number of errors in the logs relating to OpenTelemetry, however the predominate one is:

WARNING org.eclipse.jetty.server.handler.ContextHandler$Context log
Error while serving https://<controller_endpoint>/i18n/resourceBundle
java.lang.NullPointerException
    at com.google.common.base.Preconditions.checkNotNull(Preconditions.java:903)
    at io.jenkins.plugins.opentelemetry.OpenTelemetrySdkProvider.getResource(OpenTelemetrySdkProvider.java:82)
    at io.jenkins.plugins.opentelemetry.OpenTelemetryRootAction.lambda$getUrlName$3(OpenTelemetryRootAction.java:50)
    at java.base/java.util.Optional.map(Optional.java:265)
    at io.jenkins.plugins.opentelemetry.OpenTelemetryRootAction.getUrlName(OpenTelemetryRootAction.java:50)
    at jenkins.model.Jenkins.getDynamic(Jenkins.java:4050)
    at java.base/java.lang.invoke.MethodHandle.invokeWithArguments(MethodHandle.java:710)
    at org.kohsuke.stapler.Function$MethodFunction.invoke(Function.java:397)
Caused: java.lang.reflect.InvocationTargetException
    at org.kohsuke.stapler.Function$MethodFunction.invoke(Function.java:401)
    at org.kohsuke.stapler.Function$InstanceFunction.invoke(Function.java:409)

Additionally, I've observed the following WARNING upon startup:

WARNING i.j.p.o.b.ObservabilityBackend#getMetricsVisualizationUrl: Failure to generate MetricsVisualizationUrl, missing binding for property 'traceId' in template https://one.newrelic.com/distributed-tracing?account=<acct_id>&state=${traceId}

We believe this is due to Otel Configuration not being exported as Env vars. We can see option checked in the UI however the sections Noteworthy active configuration properties & Active resource attributes are empty. Interestingly, when clicking save from the UI, these sections populate, errors go away and the system is stable again.

Anything else?

Much of the "Manage Jenkins" UI is unreachable when when in this errored state.

Are you interested in contributing a fix?

No response

cyrille-leclerc commented 2 days ago

https://github.com/jenkinsci/opentelemetry-plugin/blob/c9dba0b34c2a939dadd9295b4969a7388bd46ff5/src/main/java/io/jenkins/plugins/opentelemetry/OpenTelemetrySdkProvider.java#L81-L83