/**
 * Copyright (C) 2006-2018 Talend Inc. - www.talend.com
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.talend.sdk.component.server.configuration;

import java.util.HashMap;
import java.util.Map;

import org.eclipse.microprofile.config.spi.ConfigSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class OpenTracingConfigSource implements ConfigSource {

    private final static Logger LOGGER = LoggerFactory.getLogger(OpenTracingConfigSource.class);

    private final String TRACING_ON = "TRACING_ON";

    private final String TRACING_SAMPLING_RATE = "TRACING_SAMPLING_RATE";

    private Map<String, String> configuration = new HashMap<String, String>() {

        {
            final boolean tracingOn =
                    System.getenv(TRACING_ON) != null && Boolean.parseBoolean(System.getenv(TRACING_ON));
            int tracingRate = 1;
            if (System.getenv(TRACING_SAMPLING_RATE) != null) {
                try {
                    tracingRate = Integer.parseInt(System.getenv(TRACING_SAMPLING_RATE));
                } catch (final NumberFormatException e) {
                    LOGGER.warn("Can't parse value of environment property TRACING_SAMPLING_RATE", e);
                }
            }
            final String isTracingOn = String.valueOf(tracingOn && tracingRate == 1);
            put("geronimo.opentracing.filter.active", isTracingOn);
            put("span.converter.zipkin.active", isTracingOn);
            put("span.converter.zipkin.logger.active", isTracingOn);
        }
    };

    @Override
    public Map<String, String> getProperties() {
        return configuration;
    }

    @Override
    public int getOrdinal() {
        return 2000;
    }

    @Override
    public String getValue(final String propertyName) {
        return configuration.get(propertyName);
    }

    @Override
    public String getName() {
        return "talend-opentracing";
    }
}

@@ -667,16 +667,101 @@
 ation;%0A%0A
+import static java.lang.System.getenv;%0Aimport static java.util.Optional.ofNullable;%0A%0A
 import j
@@ -1082,136 +1082,8 @@
 );%0A%0A
-    private final String TRACING_ON = %22TRACING_ON%22;%0A%0A    private final String TRACING_SAMPLING_RATE = %22TRACING_SAMPLING_RATE%22;%0A%0A
     
@@ -1185,29 +1185,19 @@
     
-f
 in
-al boolean
+t
  tracing
 On =
@@ -1196,15 +1196,14 @@
 cing
-On =%0A  
+Rate;%0A
     
@@ -1214,100 +1214,17 @@
     
-      System.getenv(TRACING_ON) != null && Boolean.parseBoolean(System.getenv(TRACING_ON));%0A
+try %7B%0A   
     
@@ -1223,35 +1223,32 @@
 %0A               
-int
  tracingRate = 1
@@ -1250,41 +1250,27 @@
 e = 
-1;%0A            if (System.
+ofNullable(
 getenv(
+%22
 TRAC
@@ -1290,93 +1290,33 @@
 RATE
-) != null) %7B%0A                try %7B%0A                    tracingRate = 
+%22)).map(
 Integer
-.
+::
 parseInt
 (Sys
@@ -1315,52 +1315,21 @@
 eInt
-(System.getenv(TRACING_SAMPLING_RATE));%0A    
+).orElse(1);%0A
     
@@ -1374,28 +1374,24 @@
 eption e) %7B%0A
-    
             
@@ -1485,33 +1485,48 @@
                 
-%7D
+tracingRate = 1;
 %0A            %7D%0A 
@@ -1520,24 +1520,25 @@
           %7D%0A
+%0A
             
@@ -1583,17 +1583,50 @@
 eOf(
-tracingOn
+Boolean.parseBoolean(getenv(%22TRACING_ON%22))
  && 

simplify opentracing source config init