|
| 1 | +/* |
| 2 | + * Copyright Splunk Inc. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package com.splunk.opentelemetry; |
| 18 | + |
| 19 | +import static io.opentelemetry.api.common.AttributeKey.stringKey; |
| 20 | + |
| 21 | +import com.google.auto.service.AutoService; |
| 22 | +import io.opentelemetry.api.common.AttributeKey; |
| 23 | +import io.opentelemetry.api.common.Attributes; |
| 24 | +import io.opentelemetry.api.incubator.config.DeclarativeConfigProperties; |
| 25 | +import io.opentelemetry.sdk.autoconfigure.spi.internal.ComponentProvider; |
| 26 | +import io.opentelemetry.sdk.resources.Resource; |
| 27 | + |
| 28 | +@AutoService(ComponentProvider.class) |
| 29 | +public class AppDynamicsVersionResourceDetector implements ComponentProvider { |
| 30 | + static final AttributeKey<String> APPD_AGENT_VER_KEY = stringKey("appdynamics.agent.version"); |
| 31 | + |
| 32 | + @Override |
| 33 | + public Class<Resource> getType() { |
| 34 | + return Resource.class; |
| 35 | + } |
| 36 | + |
| 37 | + @Override |
| 38 | + public String getName() { |
| 39 | + return "appd_agent_version"; |
| 40 | + } |
| 41 | + |
| 42 | + @Override |
| 43 | + public Resource create(DeclarativeConfigProperties config) { |
| 44 | + // When AppD Agent starts Splunk Agent then it passes its version to Splunk Agent as a system |
| 45 | + // property |
| 46 | + String version = System.getProperty(APPD_AGENT_VER_KEY.getKey()); |
| 47 | + if (version == null) { |
| 48 | + return Resource.empty(); |
| 49 | + } |
| 50 | + |
| 51 | + Attributes attributes = Attributes.of(APPD_AGENT_VER_KEY, version); |
| 52 | + return Resource.create(attributes); |
| 53 | + } |
| 54 | +} |
0 commit comments