1// Licensed to the Software Freedom Conservancy (SFC) under one2// or more contributor license agreements. See the NOTICE file3// distributed with this work for additional information4// regarding copyright ownership. The SFC licenses this file5// to you under the Apache License, Version 2.0 (the6// "License"); you may not use this file except in compliance7// with the License. You may obtain a copy of the License at8//9// http://www.apache.org/licenses/LICENSE-2.010//11// Unless required by applicable law or agreed to in writing,12// software distributed under the License is distributed on an13// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY14// KIND, either express or implied. See the License for the15// specific language governing permissions and limitations16// under the License.17package org.openqa.selenium.remote.tracing;18import io.opentracing.contrib.tracerresolver.TracerResolver;19import io.opentracing.noop.NoopTracerFactory;20import java.util.Map;21import java.util.Objects;22import java.util.function.Function;23/**24 * Represents an entry point for accessing all aspects of distributed tracing.25 */26public interface DistributedTracer {27 static Builder builder() {28 return new Builder();29 }30 /**31 * A distributed trace is made of a series of {@link Span}s, which are either32 * independent or have a parent/child relationship. Creating a span will make33 * it the currently active {@code Span}, as returned by34 * {@link #getActiveSpan()}.35 *36 * @param parent The parent span. If this is {@code null}, then the span is37 * assumed to be independent.38 */39 Span createSpan(String operation, Span parent);40 /**41 * Create a span from a remote context of some type, which will generally be42 * an {@link org.openqa.selenium.remote.http.HttpRequest}.43 */44 <C> Span createSpan(String operationName, C carrier, Function<C, Map<String, String>> extractor);45 /**46 * Get the currently active span, which may be {@code null}.47 */48 Span getActiveSpan();49 class Builder {50 private DistributedTracer tracer;51 private Builder() {52 // Only accessible through the parent class53 this.tracer = new OpenTracingTracer(NoopTracerFactory.create());54 }55 public Builder use(io.opentracing.Tracer openTracingTracer) {56 Objects.requireNonNull(openTracingTracer, "Tracer must be set.");57 tracer = new OpenTracingTracer(openTracingTracer);58 return this;59 }60 public Builder detect() {61 // Checking the global tracer is futile --- it defaults to a no-op instance.62 try {63 this.tracer = new OpenTracingTracer(TracerResolver.resolveTracer());64 } catch (Throwable e) {65 // Fine. Leave the tracer as it is.66 }67 return this;68 }69 public DistributedTracer build() {70 return tracer;71 }72 }73}...