-
Notifications
You must be signed in to change notification settings - Fork 325
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement context_propagation_only setting (#3358)
- Loading branch information
Showing
11 changed files
with
178 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
...t-core/src/main/java/co/elastic/apm/agent/impl/transaction/AbstractRefCountedContext.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
* Licensed to Elasticsearch B.V. under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch B.V. 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 co.elastic.apm.agent.impl.transaction; | ||
|
||
import co.elastic.apm.agent.tracer.pooling.Recyclable; | ||
import co.elastic.apm.agent.impl.ElasticApmTracer; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.util.concurrent.atomic.AtomicInteger; | ||
|
||
public abstract class AbstractRefCountedContext<T extends AbstractRefCountedContext<T>> extends ElasticContext<T> implements Recyclable { | ||
private static final Logger logger = LoggerFactory.getLogger(AbstractRefCountedContext.class); | ||
|
||
private final AtomicInteger references = new AtomicInteger(); | ||
|
||
protected AbstractRefCountedContext(ElasticApmTracer tracer) { | ||
super(tracer); | ||
} | ||
|
||
@Override | ||
public void incrementReferences() { | ||
int referenceCount = references.incrementAndGet(); | ||
if (logger.isDebugEnabled()) { | ||
logger.debug("increment references to {} ({})", this, referenceCount); | ||
if (logger.isTraceEnabled()) { | ||
logger.trace("incrementing references at", | ||
new RuntimeException("This is an expected exception. Is just used to record where the reference count has been incremented.")); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
public void decrementReferences() { | ||
int referenceCount = references.decrementAndGet(); | ||
if (logger.isDebugEnabled()) { | ||
logger.debug("decrement references to {} ({})", this, referenceCount); | ||
if (logger.isTraceEnabled()) { | ||
logger.trace("decrementing references at", | ||
new RuntimeException("This is an expected exception. Is just used to record where the reference count has been decremented.")); | ||
} | ||
} | ||
if (referenceCount == 0) { | ||
recycle(); | ||
} | ||
} | ||
|
||
public boolean isReferenced() { | ||
return references.get() > 0; | ||
} | ||
|
||
public int getReferenceCount() { | ||
return references.get(); | ||
} | ||
|
||
protected abstract void recycle(); | ||
|
||
@Override | ||
public void resetState() { | ||
references.set(0); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.