-
Notifications
You must be signed in to change notification settings - Fork 316
CAUSEWAY-3975: Open Telemetry Integration #3464
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
andi-huber
wants to merge
28
commits into
main
Choose a base branch
from
3975-telemetry
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 27 commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
d71ecb5
CAUSEWAY-3975: Open Telemetry Integration
andi-huber 743a259
CAUSEWAY-3975: work on simplified InteractionService
andi-huber 67f8b8d
CAUSEWAY-3975: consolidating custom request processing logic (wicket)
andi-huber b48185e
CAUSEWAY-3975: interaction is too short lived
andi-huber 1002386
CAUSEWAY-3975: interaction creation fixes
andi-huber e1ee5c6
CAUSEWAY-3975: proper observation scope closing
andi-huber 88c5a0b
CAUSEWAY-3975: factors out RehydrationHandler
andi-huber b5a170b
CAUSEWAY-3975: adds observation 'Causeway Layered Interaction'
andi-huber 7258e3d
CAUSEWAY-3975: cleaning up
andi-huber ee86612
CAUSEWAY-3975: separation of concerns (mm init)
andi-huber 292dcd1
CAUSEWAY-3975: revert intro of TestSupport (1)
andi-huber 708bbcb
CAUSEWAY-3975: revert intro of TestSupport (2)
andi-huber 1479476
CAUSEWAY-3975: adds default
andi-huber a6a24de
CAUSEWAY-3975: adds request path to top level observation name
andi-huber 125820d
CAUSEWAY-3975: on interaction start provide user info
andi-huber 22c2176
CAUSEWAY-3975: renaming integration
andi-huber 0dfb7f4
CAUSEWAY-3975: adds transaction observation
andi-huber ed6a660
CAUSEWAY-3975: use prefix for causeway tags
andi-huber 430e258
CAUSEWAY-3975: adds telemetries for JpaEntityFacet
andi-huber 3b6508a
CAUSEWAY-3975: proper span exporting filter
andi-huber 7fd5e40
CAUSEWAY-3975: ajax detector
andi-huber a33c792
CAUSEWAY-3975: report interaction details (locale, clock, ..)
andi-huber ce13999
CAUSEWAY-3975: observe member execution (act invoke, prop change)
andi-huber 3f12327
CAUSEWAY-3975: observe execution publishing
andi-huber 60d7627
CAUSEWAY-3975: observing CausewayInteraction (wip)
andi-huber 422f4a7
CAUSEWAY-3975: moves CausewayObservationIntegration to config, so we can
andi-huber 1cb8252
CAUSEWAY-3975: fleshes out CausewayObservationAutoConfiguration
andi-huber 442a90e
CAUSEWAY-3975: consolidates observation configuration in single class
andi-huber File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
103 changes: 103 additions & 0 deletions
103
...b/src/main/java/org/apache/causeway/applib/services/iactnlayer/InteractionLayerStack.java
This file contains hidden or 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,103 @@ | ||
| /* | ||
| * 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 org.apache.causeway.applib.services.iactnlayer; | ||
|
|
||
| import java.util.Optional; | ||
| import java.util.function.Predicate; | ||
|
|
||
| import org.jspecify.annotations.Nullable; | ||
|
|
||
| import org.apache.causeway.applib.services.iactn.Interaction; | ||
| import org.apache.causeway.commons.internal.observation.ObservationClosure; | ||
|
|
||
| import io.micrometer.observation.Observation; | ||
|
|
||
| public final class InteractionLayerStack { | ||
|
|
||
| // TODO: reading the javadoc for TransactionSynchronizationManager and looking at the implementations | ||
| // of TransactionSynchronization (in particular SpringSessionSynchronization), I suspect that this | ||
| // ThreadLocal would be considered bad practice and instead should be managed using the TransactionSynchronization mechanism. | ||
| private final ThreadLocal<InteractionLayer> threadLocalLayer = new ThreadLocal<>(); | ||
|
|
||
| public Optional<InteractionLayer> currentLayer() { | ||
| return Optional.ofNullable(threadLocalLayer.get()); | ||
| } | ||
|
|
||
| public InteractionLayer push( | ||
| final Interaction interaction, | ||
| final InteractionContext interactionContext, | ||
| final Observation observation) { | ||
| var parent = currentLayer().orElse(null); | ||
| @SuppressWarnings("resource") | ||
| var newLayer = new InteractionLayer(parent, interaction, interactionContext, | ||
| // on-close callback | ||
| new ObservationClosure().startAndOpenScope(observation)::close); | ||
| threadLocalLayer.set(newLayer); | ||
| return newLayer; | ||
| } | ||
|
|
||
| public void clear() { | ||
| currentLayer().ifPresent(InteractionLayer::closeAll); | ||
| threadLocalLayer.remove(); | ||
| } | ||
|
|
||
| public boolean isEmpty() { | ||
| return threadLocalLayer.get()==null; | ||
| } | ||
|
|
||
| public int size() { | ||
| return currentLayer() | ||
| .map(InteractionLayer::totalLayerCount) | ||
| .orElse(0); | ||
| } | ||
|
|
||
| @Nullable | ||
| public InteractionLayer peek() { | ||
| return threadLocalLayer.get(); | ||
| } | ||
|
|
||
| @Nullable | ||
| public InteractionLayer pop() { | ||
| var current = threadLocalLayer.get(); | ||
| if(current==null) return null; | ||
|
|
||
| var newTop = current.parent(); | ||
| current.close(); | ||
| return set(newTop); | ||
| } | ||
|
|
||
| public void popWhile(final Predicate<InteractionLayer> condition) { | ||
| while(!isEmpty()) { | ||
| if(!condition.test(peek())) return; | ||
| pop(); | ||
| } | ||
| } | ||
|
|
||
| // -- HELPER | ||
|
|
||
| private InteractionLayer set(@Nullable final InteractionLayer layer) { | ||
| if(layer != null) { | ||
| threadLocalLayer.set(layer); | ||
| } else { | ||
| threadLocalLayer.remove(); | ||
| } | ||
| return layer; | ||
| } | ||
|
|
||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
96 changes: 96 additions & 0 deletions
96
...ns/src/main/java/org/apache/causeway/commons/internal/observation/ObservationClosure.java
This file contains hidden or 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,96 @@ | ||
| /* | ||
| * 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 org.apache.causeway.commons.internal.observation; | ||
|
|
||
| import java.util.function.Supplier; | ||
|
|
||
| import org.jspecify.annotations.Nullable; | ||
|
|
||
| import lombok.Getter; | ||
| import lombok.experimental.Accessors; | ||
|
|
||
| import io.micrometer.common.KeyValue; | ||
| import io.micrometer.observation.Observation; | ||
| import io.micrometer.observation.Observation.Scope; | ||
|
|
||
| /** | ||
| * Helps if start and stop of an {@link Observation} happen in different code locations. | ||
| */ | ||
| @Getter @Accessors(fluent = true) | ||
| public final class ObservationClosure implements AutoCloseable { | ||
|
|
||
| public static final KeyValue DISCARD_KEY = KeyValue.of("causeway.discard", ""); | ||
|
|
||
| private Observation observation; | ||
| private Scope scope; | ||
|
|
||
| public ObservationClosure startAndOpenScope(final Observation observation) { | ||
| if(observation==null) return this; | ||
| this.observation = observation.start(); | ||
| this.scope = observation.openScope(); | ||
| return this; | ||
| } | ||
|
|
||
| @Override | ||
| public void close() { | ||
| if(observation==null) return; | ||
| if(scope!=null) { | ||
| this.scope.close(); | ||
| this.scope = null; | ||
| } | ||
| observation.stop(); | ||
| } | ||
|
|
||
| public void onError(final Exception ex) { | ||
| if(observation==null) return; | ||
| // scope lifecycle terminates before exception handling | ||
| if(scope!=null) { | ||
| this.scope.close(); | ||
| this.scope = null; | ||
| } | ||
| observation.error(ex); | ||
| } | ||
|
|
||
| public ObservationClosure tag(final String key, @Nullable final Supplier<? extends Object> valueSupplier) { | ||
| if(observation==null || valueSupplier == null) return this; | ||
| try { | ||
| observation.highCardinalityKeyValue(key, "" + valueSupplier.get()); | ||
| } catch (Exception e) { | ||
| observation.highCardinalityKeyValue(key, "EXCEPTION: " + e.getMessage()); | ||
| } | ||
| return this; | ||
| } | ||
|
|
||
| public void discard() { | ||
| discard(this.observation); | ||
| close(); | ||
| } | ||
|
|
||
| // -- UTILITY | ||
|
|
||
| /** | ||
| * Denies span export, in collaboration with a Spring registered {@link DiscardedSpanExportingPredicate}. | ||
| */ | ||
| public static void discard(@Nullable final Observation obs) { | ||
| if(obs == null) | ||
| return; | ||
| obs.lowCardinalityKeyValue(DISCARD_KEY); | ||
| } | ||
|
|
||
| } |
This file contains hidden or 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 hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like that as the final answer, because we don't really know how to handle potential exceptions of the runnable.