From dev-return-925-archive-asf-public=cust-asf.ponee.io@zipkin.apache.org Thu Jun 13 06:20:10 2019 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [207.244.88.153]) by mx-eu-01.ponee.io (Postfix) with SMTP id D9E6C18064E for ; Thu, 13 Jun 2019 08:20:09 +0200 (CEST) Received: (qmail 26878 invoked by uid 500); 13 Jun 2019 06:20:09 -0000 Mailing-List: contact dev-help@zipkin.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@zipkin.apache.org Delivered-To: mailing list dev@zipkin.apache.org Received: (qmail 26833 invoked by uid 99); 13 Jun 2019 06:20:09 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 13 Jun 2019 06:20:09 +0000 From: GitBox To: dev@zipkin.apache.org Subject: [GitHub] [incubator-zipkin-brave] anuraaga commented on a change in pull request #924: Makes Tracer.currentSpanCustomizer() lazy Message-ID: <156040680417.26826.5953642087355806944.gitbox@gitbox.apache.org> Date: Thu, 13 Jun 2019 06:20:04 -0000 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit anuraaga commented on a change in pull request #924: Makes Tracer.currentSpanCustomizer() lazy URL: https://github.com/apache/incubator-zipkin-brave/pull/924#discussion_r293220646 ########## File path: brave/src/main/java/brave/LazySpan.java ########## @@ -0,0 +1,126 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package brave; + +import brave.propagation.TraceContext; + +/** This wraps the public api and guards access to a mutable span. */ +final class LazySpan extends Span { + + final Tracer tracer; + final TraceContext context; + volatile Span delegate; + + LazySpan(Tracer tracer, TraceContext context) { + this.tracer = tracer; + this.context = context; + } + + @Override public boolean isNoop() { + return false; + } + + @Override public TraceContext context() { + return context; + } + + @Override public SpanCustomizer customizer() { + return new SpanCustomizerShield(this); + } + + @Override public Span start() { + return span().start(); + } + + @Override public Span start(long timestamp) { + return span().start(timestamp); + } + + @Override public Span name(String name) { + return span().name(name); + } + + @Override public Span kind(Kind kind) { + return span().kind(kind); + } + + @Override public Span annotate(String value) { + return span().annotate(value); + } + + @Override public Span annotate(long timestamp, String value) { + return span().annotate(timestamp, value); + } + + @Override public Span tag(String key, String value) { + return span().tag(key, value); + } + + @Override public Span error(Throwable throwable) { + return span().error(throwable); + } + + @Override public Span remoteServiceName(String remoteServiceName) { + return span().remoteServiceName(remoteServiceName); + } + + @Override public boolean remoteIpAndPort(String remoteIp, int remotePort) { + return span().remoteIpAndPort(remoteIp, remotePort); + } + + @Override public void finish() { + span().finish(); + } + + @Override public void finish(long timestamp) { + span().finish(timestamp); + } + + @Override public void abandon() { + if (delegate == null) return; // prevent resurrection + span().abandon(); + } + + @Override public void flush() { + if (delegate == null) return; // prevent resurrection + span().flush(); + } + + @Override public String toString() { + return "LazySpan(" + context + ")"; + } + + @Override public boolean equals(Object o) { + if (o == this) return true; + if (o instanceof LazySpan) { Review comment: How about a package-private method that returns the context? ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: users@infra.apache.org With regards, Apache Git Services --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@zipkin.apache.org For additional commands, e-mail: dev-help@zipkin.apache.org