@Test void shouldTraceErrors() { final DataSource dataSource = unit.trace(original); assertThrows(SQLException.class, () -> { try (final Connection connection = dataSource.getConnection(); final Statement statement = connection.createStatement()) { statement.execute("SELECT * FROM MATRIX(4)"); } }); final List<MockSpan> spans = tracer.finishedSpans(); final MockSpan span = getOnlyElement(spans); assertThat(span.operationName(), is("execute")); assertThat(span.tags(), hasEntry("component", "JDBC")); assertThat(span.tags(), hasEntry("db.statement", "SELECT * FROM MATRIX(4)")); assertThat(span.tags(), hasEntry("db.type", "sql")); assertThat(span.tags(), hasEntry("span.kind", "client")); assertThat(span.tags(), hasEntry("flow_id", "REcCvlqMSReeo7adheiYFA")); assertThat(span.tags(), hasEntry("error", true)); final List<MockSpan.LogEntry> entries = span.logEntries(); assertThat(entries, hasSize(3)); assertThat(entries.get(0).fields().get("message").toString(), containsString("Function \"MATRIX\" not found")); assertThat(entries.get(1).fields(), hasEntry("error.kind", "JdbcSQLSyntaxErrorException")); assertThat(entries.get(1).fields(), hasEntry(equalTo("error.object"), instanceOf(SQLException.class))); assertThat(entries.get(2).fields().get("stack").toString(), containsString("at org.h2.jdbc")); }
@CheckReturnValue public DataSource trace(final DataSource dataSource) { return ProxyDataSourceBuilder.create(dataSource) .listener(new TracingQueryExecutionListener( tracer, operationName, lifecycle, activation, decorator)) .build(); }
DataSourceTracer { @CheckReturnValue public DataSource trace(final DataSource dataSource) { return ProxyDataSourceBuilder.create(dataSource) .listener(new TracingQueryExecutionListener( tracer, operationName, lifecycle, activation, decorator)) .build(); } }
DataSourceTracer { @CheckReturnValue public DataSource trace(final DataSource dataSource) { return ProxyDataSourceBuilder.create(dataSource) .listener(new TracingQueryExecutionListener( tracer, operationName, lifecycle, activation, decorator)) .build(); } DataSourceTracer(final Tracer tracer); }
DataSourceTracer { @CheckReturnValue public DataSource trace(final DataSource dataSource) { return ProxyDataSourceBuilder.create(dataSource) .listener(new TracingQueryExecutionListener( tracer, operationName, lifecycle, activation, decorator)) .build(); } DataSourceTracer(final Tracer tracer); @CheckReturnValue DataSourceTracer withOperationName(
            final OperationName operationName); @CheckReturnValue DataSourceTracer withLifecycle(final Lifecycle lifecycle); @CheckReturnValue DataSourceTracer withActivation(final Activation activation); @CheckReturnValue DataSourceTracer withAdditionalSpanDecorators(
            final SpanDecorator first, final SpanDecorator... decorators); @CheckReturnValue DataSourceTracer withSpanDecorators(
            final SpanDecorator decorator, final SpanDecorator... decorators); @CheckReturnValue DataSource trace(final DataSource dataSource); }
DataSourceTracer { @CheckReturnValue public DataSource trace(final DataSource dataSource) { return ProxyDataSourceBuilder.create(dataSource) .listener(new TracingQueryExecutionListener( tracer, operationName, lifecycle, activation, decorator)) .build(); } DataSourceTracer(final Tracer tracer); @CheckReturnValue DataSourceTracer withOperationName(
            final OperationName operationName); @CheckReturnValue DataSourceTracer withLifecycle(final Lifecycle lifecycle); @CheckReturnValue DataSourceTracer withActivation(final Activation activation); @CheckReturnValue DataSourceTracer withAdditionalSpanDecorators(
            final SpanDecorator first, final SpanDecorator... decorators); @CheckReturnValue DataSourceTracer withSpanDecorators(
            final SpanDecorator decorator, final SpanDecorator... decorators); @CheckReturnValue DataSource trace(final DataSource dataSource);  }