2  * ============LICENSE_START=======================================================
 
   3  * Copyright (C) 2024 Nordix Foundation
 
   4  * ================================================================================
 
   5  * Licensed under the Apache License, Version 2.0 (the "License");
 
   6  * you may not use this file except in compliance with the License.
 
   7  * You may obtain a copy of the License at
 
   9  *       http://www.apache.org/licenses/LICENSE-2.0
 
  11  * Unless required by applicable law or agreed to in writing, software
 
  12  * distributed under the License is distributed on an "AS IS" BASIS,
 
  13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
  14  * See the License for the specific language governing permissions and
 
  15  * limitations under the License.
 
  17  * SPDX-License-Identifier: Apache-2.0
 
  18  * ============LICENSE_END=========================================================
 
  21 package org.onap.cps.ncmp.api.impl.config
 
  23 import io.opentelemetry.exporter.otlp.http.trace.OtlpHttpSpanExporter
 
  24 import io.opentelemetry.exporter.otlp.trace.OtlpGrpcSpanExporter
 
  25 import io.opentelemetry.sdk.extension.trace.jaeger.sampler.JaegerRemoteSampler
 
  26 import org.spockframework.spring.SpringBean
 
  27 import org.springframework.boot.actuate.autoconfigure.observation.ObservationRegistryCustomizer
 
  28 import spock.lang.Shared
 
  29 import spock.lang.Specification
 
  31 class OpenTelemetryConfigSpec extends Specification{
 
  35     OpenTelemetryConfig openTelemetryConfig = new OpenTelemetryConfig()
 
  38         openTelemetryConfig.tracingExporterEndpointUrl="http://tracingExporterEndpointUrl"
 
  39         openTelemetryConfig.jaegerRemoteSamplerUrl="http://jaegerremotesamplerurl"
 
  40         openTelemetryConfig.serviceId ="cps-application"
 
  43     def 'OpenTelemetryConfig Construction.'() {
 
  44         expect: 'the system can create an instance'
 
  45         new OpenTelemetryConfig() != null
 
  48     def  'OTLP Exporter creation with Grpc protocol'(){
 
  49         when: 'an OTLP exporter is created'
 
  50             def result = openTelemetryConfig.createOtlpExporterGrpc()
 
  51         then: 'an OTLP Exporter is created'
 
  52             assert result instanceof OtlpGrpcSpanExporter
 
  55     def  'OTLP Exporter creation with HTTP protocol'(){
 
  56         when: 'an OTLP exporter is created'
 
  57             def result = openTelemetryConfig.createOtlpExporterHttp()
 
  58         then: 'an OTLP Exporter is created'
 
  59             assert result instanceof OtlpHttpSpanExporter
 
  61             assert result.builder.endpoint=="http://tracingExporterEndpointUrl"
 
  64     def  'Jaeger Remote Sampler Creation'(){
 
  65         when: 'an OTLP exporter is created'
 
  66             def result = openTelemetryConfig.createJaegerRemoteSampler()
 
  67         then: 'an OTLP Exporter is created'
 
  68             assert result instanceof JaegerRemoteSampler
 
  70             assert result.delegate.type=="remoteSampling"
 
  72             assert result.delegate.url.toString().startsWith("http://jaegerremotesamplerurl")
 
  75     def  'Skipping Acutator endpoints'(){
 
  76         when: 'an OTLP exporter is created'
 
  77             def result = openTelemetryConfig.skipActuatorEndpointsFromObservation()
 
  78         then: 'an OTLP Exporter is created'
 
  79             assert result instanceof ObservationRegistryCustomizer