• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2017, OpenCensus Authors
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 io.opencensus.contrib.agent;
18 
19 import java.util.logging.Level;
20 import java.util.logging.Logger;
21 import net.bytebuddy.agent.builder.AgentBuilder;
22 import net.bytebuddy.description.type.TypeDescription;
23 import net.bytebuddy.dynamic.DynamicType;
24 import net.bytebuddy.utility.JavaModule;
25 
26 /**
27  * An {@link AgentBuilder.Listener} which uses {@link java.util.logging} for logging events of
28  * interest.
29  */
30 final class AgentBuilderListener implements AgentBuilder.Listener {
31 
32   private static final Logger logger = Logger.getLogger(AgentBuilderListener.class.getName());
33 
34   @Override
onTransformation( TypeDescription typeDescription, ClassLoader classLoader, JavaModule module, boolean loaded, DynamicType dynamicType)35   public void onTransformation(
36       TypeDescription typeDescription,
37       ClassLoader classLoader,
38       JavaModule module,
39       boolean loaded,
40       DynamicType dynamicType) {
41     logger.log(Level.FINE, "{0}", typeDescription);
42   }
43 
44   @Override
onIgnored( TypeDescription typeDescription, ClassLoader classLoader, JavaModule module, boolean loaded)45   public void onIgnored(
46       TypeDescription typeDescription,
47       ClassLoader classLoader,
48       JavaModule module,
49       boolean loaded) {}
50 
51   @Override
onError( String typeName, ClassLoader classLoader, JavaModule module, boolean loaded, Throwable throwable)52   public void onError(
53       String typeName,
54       ClassLoader classLoader,
55       JavaModule module,
56       boolean loaded,
57       Throwable throwable) {
58     logger.log(Level.WARNING, "Failed to handle " + typeName, throwable);
59   }
60 
61   @Override
onComplete( String typeName, ClassLoader classLoader, JavaModule module, boolean loaded)62   public void onComplete(
63       String typeName, ClassLoader classLoader, JavaModule module, boolean loaded) {}
64 
65   @Override
onDiscovery( String typeName, ClassLoader classLoader, JavaModule module, boolean loaded)66   public void onDiscovery(
67       String typeName, ClassLoader classLoader, JavaModule module, boolean loaded) {}
68 }
69