Java Code Examples for io.opentracing.contrib.common.WrapperProxy#wrap()

The following examples show how to use io.opentracing.contrib.common.WrapperProxy#wrap() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FixedDelayAgentRule.java    From java-specialagent with Apache License 2.0 6 votes vote down vote up
@Advice.OnMethodEnter
public static void exit(final @ClassName String className, final @Advice.Origin String origin, @Advice.Argument(value = 0, readOnly = false, typing = Typing.DYNAMIC) Runnable arg) throws Exception {
  if (!isAllowed(className, origin))
    return;

  final Tracer tracer = GlobalTracer.get();
  if (isVerbose(className)) {
    final Span span = tracer
      .buildSpan("scheduleWithFixedDelay")
      .withTag(Tags.COMPONENT, "java-concurrent")
      .start();
    arg = WrapperProxy.wrap(arg, new TracedRunnable(arg, span, true));
    span.finish();
  }
  else if (tracer.activeSpan() != null) {
    arg = WrapperProxy.wrap(arg, new TracedRunnable(arg, tracer.activeSpan(), false));
  }
}
 
Example 2
Source File: TracingDataSource.java    From java-jdbc with Apache License 2.0 6 votes vote down vote up
@Override
public Connection getConnection(final String username, final String password)
    throws SQLException {
  final Span span = buildSpan("AcquireConnection", "", connectionInfo, withActiveSpanOnly,
      ignoreStatements, tracer);
  final Connection connection;
  try (Scope ignored = tracer.activateSpan(span)) {
    connection = underlying.getConnection(username, password);
  } catch (Exception e) {
    JdbcTracingUtils.onError(e, span);
    throw e;
  } finally {
    span.finish();
  }

  return WrapperProxy
      .wrap(connection, new TracingConnection(connection, connectionInfo, withActiveSpanOnly,
          ignoreStatements, tracer));
}
 
Example 3
Source File: FixedRateAgentRule.java    From java-specialagent with Apache License 2.0 6 votes vote down vote up
@Advice.OnMethodEnter
public static void exit(final @ClassName String className, final @Advice.Origin String origin, @Advice.Argument(value = 0, readOnly = false, typing = Typing.DYNAMIC) Runnable arg) throws Exception {
  if (!isAllowed(className, origin))
    return;

  final Tracer tracer = GlobalTracer.get();
  if (isVerbose(className)) {
    final Span span = tracer
      .buildSpan("scheduleAtFixedRate")
      .withTag(Tags.COMPONENT, "java-concurrent")
      .start();
    arg = WrapperProxy.wrap(arg, new TracedRunnable(arg, span, true));
    span.finish();
  }
  else if (tracer.activeSpan() != null) {
    arg = WrapperProxy.wrap(arg, new TracedRunnable(arg, tracer.activeSpan(), false));
  }
}
 
Example 4
Source File: SpymemcachedAgentIntercept.java    From java-specialagent with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
public static Object get(final Object key, final Object callback) {
  final SpanBuilder spanBuilder = spanBuilder("get");
  if (key instanceof Collection) {
    final Iterator<? extends CharSequence> iterator = ((Collection<? extends CharSequence>)key).iterator();
    final StringBuilder builder = new StringBuilder();
    for (int i = 0; iterator.hasNext(); ++i) {
      if (i > 0)
        builder.append(',');

      builder.append(iterator.next());
    }

    spanBuilder.withTag("keys", builder.toString());
  }
  else {
    spanBuilder.withTag("key", key.toString()).start();
  }

  final Span span = spanBuilder.start();
  return WrapperProxy.wrap(callback, new TracingGetOperationCallback((GetOperation.Callback)callback, span));
}
 
Example 5
Source File: TracingConnection.java    From java-jdbc with Apache License 2.0 5 votes vote down vote up
@Override
public CallableStatement prepareCall(String sql) throws SQLException {
  final CallableStatement statement = connection.prepareCall(sql);
  return WrapperProxy.wrap(statement,
      new TracingCallableStatement(connection.prepareCall(sql), sql, connectionInfo,
          withActiveSpanOnly, ignoredStatements, tracer));
}
 
Example 6
Source File: TracingConnection.java    From java-jdbc with Apache License 2.0 5 votes vote down vote up
@Override
public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency,
    int resultSetHoldability) throws SQLException {
  final PreparedStatement statement = connection
      .prepareStatement(sql, resultSetType, resultSetConcurrency, resultSetHoldability);
  return WrapperProxy.wrap(statement, new TracingPreparedStatement(statement,
      sql, connectionInfo, withActiveSpanOnly, ignoredStatements, tracer));
}
 
Example 7
Source File: TracingConnection.java    From java-jdbc with Apache License 2.0 5 votes vote down vote up
@Override
public Statement createStatement(int resultSetType, int resultSetConcurrency)
    throws SQLException {
  final Statement statement = connection.createStatement(resultSetType, resultSetConcurrency);
  return WrapperProxy.wrap(statement, new TracingStatement(statement,
      connectionInfo, withActiveSpanOnly, ignoredStatements, tracer));
}
 
Example 8
Source File: TracingConnection.java    From java-jdbc with Apache License 2.0 5 votes vote down vote up
@Override
public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency)
    throws SQLException {
  final PreparedStatement statement = connection
      .prepareStatement(sql, resultSetType, resultSetConcurrency);
  return WrapperProxy.wrap(statement, new TracingPreparedStatement(statement, sql, connectionInfo,
      withActiveSpanOnly, ignoredStatements, tracer));
}
 
Example 9
Source File: TracingDriver.java    From java-jdbc with Apache License 2.0 5 votes vote down vote up
@Override
public Connection connect(String url, Properties info) throws SQLException {
  // if there is no url, we have problems
  if (url == null) {
    throw new SQLException("url is required");
  }

  final Set<String> ignoreStatements;
  final boolean withActiveSpanOnly;
  if (interceptorMode) {
    withActiveSpanOnly = TracingDriver.withActiveSpanOnly;
    ignoreStatements = TracingDriver.ignoreStatements;
  } else if (acceptsURL(url)) {
    withActiveSpanOnly = url.contains(WITH_ACTIVE_SPAN_ONLY);
    ignoreStatements = extractIgnoredStatements(url);
  } else {
    return null;
  }

  url = extractRealUrl(url);

  // find the real driver for the URL
  final Driver wrappedDriver = findDriver(url);

  final Tracer currentTracer = getTracer();
  final ConnectionInfo connectionInfo = URLParser.parser(url);
  final Span span = buildSpan("AcquireConnection", "", connectionInfo, withActiveSpanOnly,
      Collections.<String>emptySet(), currentTracer);
  final Connection connection;
  try (Scope ignored = currentTracer.activateSpan(span)) {
    connection = wrappedDriver.connect(url, info);
  } finally {
    span.finish();
  }

  return WrapperProxy
      .wrap(connection, new TracingConnection(connection, connectionInfo, withActiveSpanOnly,
          ignoreStatements, currentTracer));
}
 
Example 10
Source File: TracingConnection.java    From java-jdbc with Apache License 2.0 4 votes vote down vote up
@Override
public PreparedStatement prepareStatement(String sql, String[] columnNames) throws SQLException {
  final PreparedStatement statement = connection.prepareStatement(sql, columnNames);
  return WrapperProxy.wrap(statement, new TracingPreparedStatement(statement, sql, connectionInfo,
      withActiveSpanOnly, ignoredStatements, tracer));
}
 
Example 11
Source File: TracingConnection.java    From java-jdbc with Apache License 2.0 4 votes vote down vote up
@Override
public PreparedStatement prepareStatement(String sql) throws SQLException {
  final PreparedStatement statement = connection.prepareStatement(sql);
  return WrapperProxy.wrap(statement, new TracingPreparedStatement(statement, sql, connectionInfo,
      withActiveSpanOnly, ignoredStatements, tracer));
}
 
Example 12
Source File: SpymemcachedAgentIntercept.java    From java-specialagent with Apache License 2.0 4 votes vote down vote up
public static Object getAndTouch(final Object key, final Object callback) {
  final Span span = spanBuilder("getAndTouch").withTag("key", key.toString()).start();
  return WrapperProxy.wrap(callback, new TracingGetAndTouchOperationCallback((OperationCallback)callback, span));
}
 
Example 13
Source File: SpymemcachedAgentIntercept.java    From java-specialagent with Apache License 2.0 4 votes vote down vote up
public static Object gets(final Object key, final Object callback) {
  final Span span = spanBuilder("gets").withTag("key", key.toString()).start();
  return WrapperProxy.wrap(callback, new TracingGetsOperationCallback((OperationCallback)callback, span));
}
 
Example 14
Source File: SpymemcachedAgentIntercept.java    From java-specialagent with Apache License 2.0 4 votes vote down vote up
public static Object cas(final Object key, final Object callback) {
  final Span span = spanBuilder("cas").withTag("key", key.toString()).start();
  return WrapperProxy.wrap(callback, new TracingStoreOperationCallback((OperationCallback)callback, span));
}
 
Example 15
Source File: ThriftAgentIntercept.java    From java-specialagent with Apache License 2.0 4 votes vote down vote up
public static Object getProcessor(final Object processor) {
  return WrapperProxy.wrap(processor, new SpanProcessor((TProcessor)processor));
}
 
Example 16
Source File: HazelcastAgentIntercept.java    From java-specialagent with Apache License 2.0 4 votes vote down vote up
public static Object getOneInstance(final Object returned) {
  return returned == null ? null : WrapperProxy.wrap(returned, new TracingHazelcastInstance((HazelcastInstance)returned, false));
}
 
Example 17
Source File: JmsAgentRule.java    From java-specialagent with Apache License 2.0 4 votes vote down vote up
@Advice.OnMethodExit
public static void enter(final @ClassName String className, final @Advice.Origin String origin, @Advice.Return(readOnly = false, typing = Typing.DYNAMIC) Object returned) {
  if (isAllowed(className, origin) && !WrapperProxy.isWrapper(returned))
    returned = WrapperProxy.wrap(returned, JmsAgentIntercept.createProducer(returned));
}
 
Example 18
Source File: CassandraAgentIntercept.java    From java-specialagent with Apache License 2.0 4 votes vote down vote up
public static Object exit(final Object thiz) {
  return WrapperProxy.wrap(thiz, new TracingSession((Session)thiz, GlobalTracer.get()));
}
 
Example 19
Source File: SpringSchedulingAgentIntercept.java    From java-specialagent with Apache License 2.0 4 votes vote down vote up
public static Object invoke(final Object arg) {
  return WrapperProxy.wrap(arg, new TracingMethodInvocation((MethodInvocation)arg));
}
 
Example 20
Source File: RabbitMQAgentIntercept.java    From java-specialagent with Apache License 2.0 4 votes vote down vote up
public static Object enterConsume(final Object callback, final Object queue) {
  return WrapperProxy.wrap(callback, new TracingConsumer((Consumer)callback, (String)queue, GlobalTracer.get()));
}