Skip to content
This repository was archived by the owner on Jan 9, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

## [0.0.11] - 2021-10-06

### Bugfixes
- Fixed issue with AWS lambda logging dependencies not included if the wrapper is used as a direct dependency

### Enhancements
- Added info message if logging exporter is installed for debug purposes
- Default value of the configuration property `otel.lib.log.level` set to `INFO`

## [0.0.10] - 2021-10-05

### Bugfixes
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ template. For more information, see the [example](./examples/splunk-wrapper/READ
OTEL_EXPORTER_JAEGER_ENDPOINT=http://127.0.0.1:9080/v1/trace
SPLUNK_ACCESS_TOKEN="orgAccessToken"
```
You can also use the `jaeger-thrift-splunk' exporter to send spans directly to the Splunk Observability Cloud backend. You can update accomplish this by updating OTEL_EXPORTER_JAEGER_ENDPOINT to the ingest URL.
You can also use the `jaeger-thrift-splunk` exporter to send spans directly to the Splunk Observability Cloud backend. You can accomplish this by updating OTEL_EXPORTER_JAEGER_ENDPOINT to the ingest URL.

```
OTEL_TRACES_EXPORTER=jaeger-thrift-splunk
Expand Down
18 changes: 14 additions & 4 deletions TROUBLESHOOTING.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
# Troubleshooting

A couple of notes what to consider in case of troubles:
- wrapper needs to be configured - consult [examples](./examples)
- wrapper will only wait configured (`OTEL_INSTRUMENTATION_AWS_LAMBDA_FLUSH_TIMEOUT`) number of milliseconds for backend
to ingest spans
- setting `OTEL_LAMBDA_LOG_LEVEL` to `debug` will install logging exporter along with the configured one
1. Verifying configuration.

Each lambda needs to be configured - consult [examples](./examples).
Pay attention to appropriate wrapper - depends on the handler type and trigger used (four different wrappers available).

2. Ensuring that traces are ingested.

Wrapper will only wait configured (`OTEL_INSTRUMENTATION_AWS_LAMBDA_FLUSH_TIMEOUT`) number of milliseconds for backend to ingest the spans. Increase the value if you don't see the spans in the APM.

3. Verifying traces in the APM.

Setting `OTEL_LAMBDA_LOG_LEVEL` to `DEBUG` will install logging exporter along with the configured one. Logging exporter will, in turn, log every span including traceId and spanId. TraceId can be then used in the APM to check if the trace was properly ingested.

The setting will also cause `jaeger-thrift-exporter` (if used) to log each trace sent to the APM along with the backend URL and token (masked) used by the operation.
2 changes: 0 additions & 2 deletions wrapper/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -215,13 +215,11 @@
<groupId>com.amazonaws</groupId>
<artifactId>aws-lambda-java-log4j2</artifactId>
<version>1.2.0</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j18-impl</artifactId>
<version>2.13.0</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ private static boolean isConfigured(String name) {
return (System.getProperty(name) != null || System.getenv(toEnvVarName(name)) != null);
}

static String getValueOrDefault(String name) {
static String getValue(String name) {

String result = System.getProperty(name);
if (result == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package com.splunk.support.lambda.configuration;

import static com.splunk.support.lambda.configuration.Config.getValueOrDefault;
import static com.splunk.support.lambda.configuration.Config.getValue;

import io.opentelemetry.semconv.resource.attributes.ResourceAttributes;
import org.slf4j.Logger;
Expand All @@ -27,7 +27,7 @@ public class ConfigValidator {
private static final Logger log = LoggerFactory.getLogger(ConfigValidator.class);

static void validate() {
String resourceAttributes = getValueOrDefault("otel.resource.attributes");
String resourceAttributes = getValue("otel.resource.attributes");
if (!resourceAttributes.contains(ResourceAttributes.SERVICE_NAME.getKey())) {
log.warn(
"Resource attribute 'service.name' is not set: your service is unnamed and will be difficult to identify."
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
package com.splunk.support.lambda.configuration;

import static com.splunk.support.lambda.configuration.Config.setDefaultValue;
import static com.splunk.support.lambda.configuration.Names.OTEL_LIB_LOG_LEVEL;
import static com.splunk.support.lambda.configuration.Names.OTEL_TRACES_EXPORTER;

public class DefaultConfiguration {

Expand All @@ -36,12 +38,15 @@ static void applyDefaults() {
setDefaultValue("otel.metrics.exporter", "none");

setDefaultValue("otel.propagators", "tracecontext,baggage");
setDefaultValue("otel.traces.exporter", "otlp");
setDefaultValue(OTEL_TRACES_EXPORTER, "otlp");

// sample ALL
setDefaultValue("otel.traces.sampler", "always_on");

// disable non-lambda resource providers
setDefaultValue("otel.java.disabled.resource.providers", DISABLED_RESOURCE_PROVIDERS);

// default info logging for otel libs
setDefaultValue(OTEL_LIB_LOG_LEVEL, "INFO");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package com.splunk.support.lambda.configuration;

import static com.splunk.support.lambda.configuration.SplunkConfiguration.SPLUNK_ACCESS_TOKEN;
import static com.splunk.support.lambda.configuration.Names.SPLUNK_ACCESS_TOKEN;
import static io.opentelemetry.api.internal.StringUtils.isNullOrEmpty;

import com.google.auto.service.AutoService;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright Splunk Inc.
*
* 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 com.splunk.support.lambda.configuration;

public final class Names {

public static final String SPLUNK_ACCESS_TOKEN = "splunk.access.token";

public static final String OTEL_LIB_LOG_LEVEL = "otel.lib.log.level";
public static final String OTEL_TRACES_EXPORTER = "otel.traces.exporter";
public static final String OTEL_EXPORTER_OTLP_HEADERS = "otel.exporter.otlp.headers";

private Names() {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,13 @@

package com.splunk.support.lambda.configuration;

import static com.splunk.support.lambda.configuration.Config.getValueOrDefault;
import static com.splunk.support.lambda.configuration.Config.getValue;
import static com.splunk.support.lambda.configuration.Names.OTEL_EXPORTER_OTLP_HEADERS;
import static com.splunk.support.lambda.configuration.Names.OTEL_LIB_LOG_LEVEL;
import static com.splunk.support.lambda.configuration.Names.OTEL_TRACES_EXPORTER;
import static com.splunk.support.lambda.configuration.Names.SPLUNK_ACCESS_TOKEN;

import io.opentelemetry.api.internal.StringUtils;
import java.util.logging.ConsoleHandler;
import java.util.logging.Handler;
import java.util.logging.Level;
Expand All @@ -29,9 +34,6 @@ public class SplunkConfiguration {

private static final Logger log = LoggerFactory.getLogger(SplunkConfiguration.class);

static final String OTEL_LIB_LOG_LEVEL = "OTEL_LIB_LOG_LEVEL";
static final String SPLUNK_ACCESS_TOKEN = "splunk.access.token";

public static void configure() {
ConfigValidator.validate();
DefaultConfiguration.applyDefaults();
Expand All @@ -40,14 +42,14 @@ public static void configure() {
}

private static void addSplunkAccessTokenToOtlpHeadersIfNeeded() {
String accessToken = getValueOrDefault(SPLUNK_ACCESS_TOKEN);
String tracesExporter = getValueOrDefault("otel.traces.exporter");
String accessToken = getValue(SPLUNK_ACCESS_TOKEN);
String tracesExporter = getValue(OTEL_TRACES_EXPORTER);

if ("otlp".equals(tracesExporter) && !accessToken.isEmpty()) {
String userOtlpHeaders = getValueOrDefault("otel.exporter.otlp.headers");
String userOtlpHeaders = getValue(OTEL_EXPORTER_OTLP_HEADERS);
String otlpHeaders =
(userOtlpHeaders.isEmpty() ? "" : userOtlpHeaders + ",") + "X-SF-TOKEN=" + accessToken;
System.setProperty("otel.exporter.otlp.headers", otlpHeaders);
System.setProperty(OTEL_EXPORTER_OTLP_HEADERS, otlpHeaders);
}
}

Expand All @@ -66,8 +68,8 @@ private static void configureOtelLogging() {
}

private static Level getOtelLibLogLevel() {
String level = System.getenv(OTEL_LIB_LOG_LEVEL);
if (level != null) {
String level = Config.getValue(OTEL_LIB_LOG_LEVEL);
if (!StringUtils.isNullOrEmpty(level)) {
try {
return Level.parse(level);
} catch (IllegalArgumentException iae) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,20 @@
import io.opentelemetry.sdk.autoconfigure.spi.SdkTracerProviderConfigurer;
import io.opentelemetry.sdk.trace.SdkTracerProviderBuilder;
import io.opentelemetry.sdk.trace.export.SimpleSpanProcessor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@AutoService(SdkTracerProviderConfigurer.class)
public class TracerProviderConfigurer implements SdkTracerProviderConfigurer {

private static final String OTEL_LAMBDA_LOG_LEVEL = "OTEL_LAMBDA_LOG_LEVEL";

private static final Logger logger = LoggerFactory.getLogger(TracerProviderConfigurer.class);

@Override
public void configure(SdkTracerProviderBuilder sdkTracerProviderBuilder) {
if (!"DEBUG".equalsIgnoreCase(System.getenv(OTEL_LAMBDA_LOG_LEVEL))) {

if (!"DEBUG".equalsIgnoreCase(Config.getValue(OTEL_LAMBDA_LOG_LEVEL))) {
return;
}

Expand All @@ -40,10 +45,11 @@ private static void maybeEnableLoggingExporter(SdkTracerProviderBuilder builder)
// don't install another instance if the user has already explicitly requested it.
if (loggingExporterIsNotAlreadyConfigured()) {
builder.addSpanProcessor(SimpleSpanProcessor.create(new LoggingSpanExporter()));
logger.info("Added logging exporter for debug purposes.");
}
}

private static boolean loggingExporterIsNotAlreadyConfigured() {
return !"logging".equalsIgnoreCase(System.getenv("OTEL_TRACES_EXPORTER"));
return !"logging".equalsIgnoreCase(Config.getValue("OTEL_TRACES_EXPORTER"));
}
}