Skip to content

Commit

Permalink
Create UserExcludedClassLoadersConfigurer; add documentation for otel…
Browse files Browse the repository at this point in the history
….javaagent.exclude-classLoaders property
  • Loading branch information
anhermon committed Jan 7, 2024
1 parent a574bc4 commit 5e55412
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
8 changes: 8 additions & 0 deletions docs/advanced-configuration-options.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ which could have unknown side-effects.
| ------------------------------ | ------------------------------ | -------------------------------------------------------------------------------------------------- |
| otel.javaagent.exclude-classes | OTEL_JAVAAGENT_EXCLUDE_CLASSES | Suppresses all instrumentation for specific classes, format is "my.package.MyClass,my.package2.\*" |

## Excluding specific classes loaders

This can be used to Ignore the class loader specified and exclude it from being instrumented.

| System property | Environment variable | Purpose |
| ------------------------------ |-------------------------------------|---------------------------------------------------------------------------------|
| otel.javaagent.exclude-classLoaders | OTEL_JAVAAGENT_EXCLUDE_CLASSLOADERS | Ignore the specified class loaders, format is "my.package.MyClass,my.package2." |

## Running application with security manager

This option can be used to let agent run with all privileges without being affected by security policy restricting some operations.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.javaagent.tooling.ignore;

import static java.util.Collections.emptyList;

import com.google.auto.service.AutoService;
import io.opentelemetry.javaagent.extension.ignore.IgnoredTypesBuilder;
import io.opentelemetry.javaagent.extension.ignore.IgnoredTypesConfigurer;
import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties;
import java.util.List;

@AutoService(IgnoredTypesConfigurer.class)
class UserExcludedClassLoadersConfigurer implements IgnoredTypesConfigurer {

// visible for tests
static final String EXCLUDED_CLASSLOADERS_CONFIG = "otel.javaagent.exclude-classLoaders";

@Override
public void configure(IgnoredTypesBuilder builder, ConfigProperties config) {
List<String> excludedClassLoaders = config.getList(EXCLUDED_CLASSLOADERS_CONFIG, emptyList());
for (String excludedClassLoader : excludedClassLoaders) {
excludedClassLoader = excludedClassLoader.trim();
// remove the trailing *
if (excludedClassLoader.endsWith("*")) {
excludedClassLoader = excludedClassLoader.substring(0, excludedClassLoader.length() - 1);
}
builder.ignoreClassLoader(excludedClassLoader);
}
}
}

0 comments on commit 5e55412

Please sign in to comment.