Skip to content
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

support event #556

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

support event #556

wants to merge 3 commits into from

Conversation

wujiaming88
Copy link

@wujiaming88 wujiaming88 commented Mar 21, 2025

Motivation:

Explain the context, and why you're making that change.
To make others understand what is the problem you're trying to solve.

Modification:

Describe the idea and modifications you've done.

Result:

Fixes #.

If there is no issue then describe the changes introduced by this PR.

Summary by CodeRabbit

  • New Features

    • Enhanced tracing functionality with improved event reporting and tagging, offering richer diagnostics and monitoring.
    • Introduced disk-based logging for span events to facilitate effective event storage and management.
  • Chores

    • Upgraded numerous components to a new development snapshot version, ensuring better alignment and stability.
  • Tests

    • Expanded test coverage for event reporting and tagging, including validations of concurrent operations.

Copy link

sofastack-cla bot commented Mar 21, 2025

Hi @wujiaming88, welcome to SOFAStack community, Please sign Contributor License Agreement!

After you signed CLA, we will automatically sync the status of this pull request in 3 minutes.

Copy link

coderabbitai bot commented Mar 21, 2025

Walkthrough

This pull request updates the version numbers in multiple Maven POM files from 3.1.9 to 3.1.10-SNAPSHOT for both parent and individual artifacts. Additionally, it introduces event reporting capabilities by adding new reporter fields and methods to the core tracing components, a new disk reporter class for span events, supplementary changes to span tagging and reporting, and corresponding tests to validate these enhancements.

Changes

File(s) Change Summary
pom.xml, .../sofa-tracer-*-plugin/pom.xml, tracer-all/pom.xml, tracer-core/pom.xml, tracer-extensions/pom.xml, tracer-sofa-boot-starter/pom.xml, tracer-test/*/pom.xml Updated version numbers from 3.1.9 to 3.1.10-SNAPSHOT in parent and project artifact declarations.
tracer-core/src/main/java/com/alipay/common/tracer/core/SofaTracer.java Added two new Reporter fields, new constructor, reportEvent method, and builder methods for configuring event reporters.
tracer-core/src/main/java/com/alipay/common/tracer/core/reporter/digest/event/SpanEventDiskReporter.java Introduced a new disk reporter class to handle span events with initialization, digest reporting, and associated getters.
tracer-core/src/main/java/com/alipay/common/tracer/core/span/SofaTracerSpan.java Added methods to set event tags (for string, boolean, and number) and a new reportEvent method for span event reporting; updated cloning to include new maps.
tracer-core/src/test/java/.../SpanEventDiskReporterTest.java
tracer-core/src/test/java/.../SofaTracerSpanTest.java
tracer-core/src/test/java/.../SofaTracerTest.java
tracer-core/src/test/java/.../ClientSpanEventEncoder.java
tracer-core/src/test/java/.../TracerTestLogEnum.java
Added new tests and a new encoder to verify and support the event reporting feature, including concurrent initialization checks and event tag validations.

Sequence Diagram(s)

Loading
sequenceDiagram
    participant Span as SofaTracerSpan
    participant Tracer as SofaTracer
    participant Reporter as SpanEventDiskReporter
    participant Appender as AsyncCommonDigestAppenderManager

    Span->>Tracer: reportEvent(span)
    alt Client Event
      Tracer->>Reporter: clientEventReporter.report(span)
    else Server Event
      Tracer->>Reporter: serverEventReporter.report(span)
    end
    Reporter->>Appender: Append span event to disk

Possibly related PRs

  • change tag to 3.1.8 #548: Involves updating the version number of the tracer-all-parent artifact, similar to the changes in this PR.
  • change tag to 3.1.9 #553: Also focuses on version number modifications in the pom.xml file, offering a direct code-level connection.
  • change tag to 3.1.9-SNAPSHOT #552: Addresses version update differences from previous versions, closely aligning with the modifications made in this PR.

Suggested labels

cla:yes, size/M

Suggested reviewers

  • ZijieSong

Poem

I’m a rabbit coding through the night,
Hopping from version bump to feature light.
Event reporters spring to life in disk‐bound cheer,
Tracing every span—from far to near.
In fields of code, I dance and play,
Celebrating each change in my rabbit way! 🐇
Happy hops and happy codes today!

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Sorry, something went wrong.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 5

🧹 Nitpick comments (3)
tracer-core/src/test/java/com/alipay/common/tracer/core/tracertest/SofaTracerTest.java (1)

79-86: Good implementation of event reporters

The initialization of both client and server event reporters follows the pattern of the existing reporter initialization. However, there are a few things to note:

  1. The server event reporter is using ClientSpanEventEncoder, which might be intentional, but consider if a separate ServerSpanEventEncoder would be more appropriate.
  2. Both reporters are initialized with empty strings for rolling policy and log reserve config, although the corresponding values are available from TracerTestLogEnum.

Consider using the enum's rolling policy and log reserve config:

-SpanEventDiskReporter clientEventReporter = new SpanEventDiskReporter(TracerTestLogEnum.RPC_CLIENT_EVENT.getDefaultLogName(), "", "", new ClientSpanEventEncoder(), null);
+SpanEventDiskReporter clientEventReporter = new SpanEventDiskReporter(TracerTestLogEnum.RPC_CLIENT_EVENT.getDefaultLogName(), 
+        TracerTestLogEnum.RPC_CLIENT_EVENT.getRollingKey(),
+        TracerTestLogEnum.RPC_CLIENT_EVENT.getLogReverseKey(), 
+        new ClientSpanEventEncoder(), null);

-SpanEventDiskReporter serverEventReporter = new SpanEventDiskReporter(TracerTestLogEnum.RPC_SERVER.getDefaultLogName(), "", "", new ClientSpanEventEncoder(), null);
+SpanEventDiskReporter serverEventReporter = new SpanEventDiskReporter(TracerTestLogEnum.RPC_SERVER.getDefaultLogName(), 
+        TracerTestLogEnum.RPC_SERVER.getRollingKey(),
+        TracerTestLogEnum.RPC_SERVER.getLogReverseKey(), 
+        new ClientSpanEventEncoder(), null);
tracer-core/src/test/java/com/alipay/common/tracer/core/tracertest/encoder/ClientSpanEventEncoder.java (1)

27-61: Well-structured event encoding implementation

The encode method logically handles each component of the span event:

  1. Timestamp
  2. Trace and Span IDs
  3. String tags
  4. Boolean tags
  5. Numeric tags
  6. Baggage

However, there are a few potential improvements:

  1. The empty string builders for boolean and numeric tags could result in trailing & characters if there are no entries
  2. There's no null checking or empty map handling for the collections

Consider adding defensive coding to handle empty maps:

// tags bool
Map<String, Boolean> tagsBool = span.getEventTagWithBool();
StringBuilder tagsBoolBuild = new StringBuilder();
-for (Map.Entry<String, Boolean> entry : tagsBool.entrySet()) {
-    tagsBoolBuild.append(entry.getKey()).append(StringUtils.EQUAL)
-            .append(entry.getValue().toString()).append(StringUtils.AND);
+if (!tagsBool.isEmpty()) {
+    for (Map.Entry<String, Boolean> entry : tagsBool.entrySet()) {
+        tagsBoolBuild.append(entry.getKey()).append(StringUtils.EQUAL)
+                .append(entry.getValue().toString()).append(StringUtils.AND);
+    }
+    // Remove trailing '&' if present
+    if (tagsBoolBuild.length() > 0 && tagsBoolBuild.charAt(tagsBoolBuild.length() - 1) == '&') {
+        tagsBoolBuild.setLength(tagsBoolBuild.length() - 1);
+    }
}
xsb.append(tagsBoolBuild.toString());

// tags number
Map<String, Number> tagsNum = span.getEventTagWithNumber();
StringBuilder tagsNumBuild = new StringBuilder();
-for (Map.Entry<String, Number> entry : tagsNum.entrySet()) {
-    tagsNumBuild.append(entry.getKey()).append(StringUtils.EQUAL)
-            .append(entry.getValue().toString()).append(StringUtils.AND);
+if (!tagsNum.isEmpty()) {
+    for (Map.Entry<String, Number> entry : tagsNum.entrySet()) {
+        tagsNumBuild.append(entry.getKey()).append(StringUtils.EQUAL)
+                .append(entry.getValue().toString()).append(StringUtils.AND);
+    }
+    // Remove trailing '&' if present
+    if (tagsNumBuild.length() > 0 && tagsNumBuild.charAt(tagsNumBuild.length() - 1) == '&') {
+        tagsNumBuild.setLength(tagsNumBuild.length() - 1);
+    }
}
xsb.append(tagsNumBuild.toString());
tracer-core/src/main/java/com/alipay/common/tracer/core/reporter/digest/event/SpanEventDiskReporter.java (1)

109-112: Empty statisticReport method.

The statisticReport method is overridden but doesn't perform any actions. It would be helpful to include a comment explaining why the method is empty.

/**
 * print stat log
 *
 * @param span span
 */
@Override
public void statisticReport(SofaTracerSpan span) {
+   // This reporter doesn't support statistical reporting, so this method intentionally does nothing
    return;
}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 53332d8 and 6c5d02b.

📒 Files selected for processing (34)
  • pom.xml (1 hunks)
  • sofa-tracer-plugins/sofa-tracer-datasource-plugin/pom.xml (1 hunks)
  • sofa-tracer-plugins/sofa-tracer-dubbo-2.6.x-plugin/pom.xml (1 hunks)
  • sofa-tracer-plugins/sofa-tracer-dubbo-common-plugin/pom.xml (1 hunks)
  • sofa-tracer-plugins/sofa-tracer-dubbo-plugin/pom.xml (1 hunks)
  • sofa-tracer-plugins/sofa-tracer-flexible-plugin/pom.xml (1 hunks)
  • sofa-tracer-plugins/sofa-tracer-httpclient-plugin/pom.xml (1 hunks)
  • sofa-tracer-plugins/sofa-tracer-kafkamq-plugin/pom.xml (1 hunks)
  • sofa-tracer-plugins/sofa-tracer-mongodb-plugin/pom.xml (1 hunks)
  • sofa-tracer-plugins/sofa-tracer-okhttp-plugin/pom.xml (1 hunks)
  • sofa-tracer-plugins/sofa-tracer-rabbitmq-plugin/pom.xml (1 hunks)
  • sofa-tracer-plugins/sofa-tracer-redis-plugin/pom.xml (1 hunks)
  • sofa-tracer-plugins/sofa-tracer-resttmplate-plugin/pom.xml (1 hunks)
  • sofa-tracer-plugins/sofa-tracer-rocketmq-plugin/pom.xml (1 hunks)
  • sofa-tracer-plugins/sofa-tracer-spring-cloud-plugin/pom.xml (1 hunks)
  • sofa-tracer-plugins/sofa-tracer-springmessage-plugin/pom.xml (1 hunks)
  • sofa-tracer-plugins/sofa-tracer-springmvc-plugin/pom.xml (1 hunks)
  • sofa-tracer-plugins/sofa-tracer-zipkin-plugin/pom.xml (1 hunks)
  • tracer-all/pom.xml (1 hunks)
  • tracer-core/pom.xml (1 hunks)
  • tracer-core/src/main/java/com/alipay/common/tracer/core/SofaTracer.java (9 hunks)
  • tracer-core/src/main/java/com/alipay/common/tracer/core/reporter/digest/event/SpanEventDiskReporter.java (1 hunks)
  • tracer-core/src/main/java/com/alipay/common/tracer/core/span/SofaTracerSpan.java (14 hunks)
  • tracer-core/src/test/java/com/alipay/common/tracer/core/reporter/digest/event/SpanEventDiskReporterTest.java (1 hunks)
  • tracer-core/src/test/java/com/alipay/common/tracer/core/span/SofaTracerSpanTest.java (24 hunks)
  • tracer-core/src/test/java/com/alipay/common/tracer/core/tracertest/SofaTracerTest.java (6 hunks)
  • tracer-core/src/test/java/com/alipay/common/tracer/core/tracertest/encoder/ClientSpanEventEncoder.java (1 hunks)
  • tracer-core/src/test/java/com/alipay/common/tracer/core/tracertest/type/TracerTestLogEnum.java (1 hunks)
  • tracer-extensions/pom.xml (1 hunks)
  • tracer-sofa-boot-starter/pom.xml (1 hunks)
  • tracer-test/core-test/pom.xml (1 hunks)
  • tracer-test/log4j-test/pom.xml (1 hunks)
  • tracer-test/log4j2-test/pom.xml (1 hunks)
  • tracer-test/logback-test/pom.xml (1 hunks)
🧰 Additional context used
🧬 Code Definitions (6)
tracer-core/src/test/java/com/alipay/common/tracer/core/tracertest/SofaTracerTest.java (1)
tracer-core/src/main/java/com/alipay/common/tracer/core/span/SofaTracerSpan.java (1) (1)
  • SofaTracerSpan (50-707)
tracer-core/src/test/java/com/alipay/common/tracer/core/tracertest/encoder/ClientSpanEventEncoder.java (1)
tracer-core/src/main/java/com/alipay/common/tracer/core/span/SofaTracerSpan.java (1) (1)
  • SofaTracerSpan (50-707)
tracer-core/src/test/java/com/alipay/common/tracer/core/reporter/digest/event/SpanEventDiskReporterTest.java (3)
tracer-core/src/main/java/com/alipay/common/tracer/core/SofaTracer.java (1) (1)
  • SofaTracer (57-555)
tracer-core/src/main/java/com/alipay/common/tracer/core/span/SofaTracerSpan.java (1) (1)
  • SofaTracerSpan (50-707)
tracer-core/src/test/java/com/alipay/common/tracer/core/tracertest/encoder/ClientSpanEventEncoder.java (1) (1)
  • ClientSpanEventEncoder (23-62)
tracer-core/src/test/java/com/alipay/common/tracer/core/span/SofaTracerSpanTest.java (3)
tracer-core/src/main/java/com/alipay/common/tracer/core/reporter/digest/event/SpanEventDiskReporter.java (1) (1)
  • SpanEventDiskReporter (28-177)
tracer-core/src/test/java/com/alipay/common/tracer/core/tracertest/encoder/ClientSpanEventEncoder.java (1) (1)
  • ClientSpanEventEncoder (23-62)
tracer-core/src/main/java/com/alipay/common/tracer/core/context/span/SofaTracerSpanContext.java (1) (1)
  • SofaTracerSpanContext (37-451)
tracer-core/src/main/java/com/alipay/common/tracer/core/reporter/digest/event/SpanEventDiskReporter.java (1)
tracer-core/src/main/java/com/alipay/common/tracer/core/span/SofaTracerSpan.java (1) (1)
  • SofaTracerSpan (50-707)
tracer-core/src/main/java/com/alipay/common/tracer/core/span/SofaTracerSpan.java (4)
tracer-core/src/main/java/com/alipay/common/tracer/core/utils/StringUtils.java (1) (1)
  • StringUtils (36-740)
tracer-core/src/main/java/com/alipay/common/tracer/core/context/span/SofaTracerSpanContext.java (1) (1)
  • SofaTracerSpanContext (37-451)
tracer-core/src/main/java/com/alipay/common/tracer/core/appender/self/SelfLog.java (1) (1)
  • SelfLog (30-153)
tracer-core/src/main/java/com/alipay/common/tracer/core/constants/SofaTracerConstant.java (1) (1)
  • SofaTracerConstant (29-125)
🔇 Additional comments (60)
tracer-test/logback-test/pom.xml (1)

7-7: Parent Version Update for Logback Test Module
The parent's version is updated to <version>3.1.10-SNAPSHOT</version>, which aligns with the new development iteration. Make sure that this update is coordinated with other modules and that there are no incompatibility issues with the dependency management.

tracer-extensions/pom.xml (1)

7-7: Verify Updated Parent Version in Tracer Extensions
The <version> element under the <parent> section has been updated to 3.1.10-SNAPSHOT, bringing it in line with other modules. Confirm that all inherited settings and dependency versions from the parent POM remain consistent and do not introduce conflicts.

sofa-tracer-plugins/sofa-tracer-springmvc-plugin/pom.xml (1)

7-7: Ensure Consistency of Parent Version in SpringMVC Plugin
The parent's version change to 3.1.10-SNAPSHOT is consistently applied. Verify that any module-specific configurations that might depend on the parent version are still valid, especially regarding relative paths and dependency management.

tracer-test/log4j-test/pom.xml (1)

7-7: Update Parent Version in Log4j Test Module
The update to <version>3.1.10-SNAPSHOT</version> for the parent artifact is applied correctly. Ensure that this change does not adversely affect the test dependencies and that all modules consuming this configuration are aligned with the new snapshot release.

tracer-test/log4j2-test/pom.xml (1)

7-7: Parent Version Alignment in Log4j2 Test Module
The parent's version field is updated to 3.1.10-SNAPSHOT, matching the broader transition across the project. It would be useful to double-check that the test scope dependencies and plugin configurations (such as for Log4j2) remain compatible with the new parent version.

sofa-tracer-plugins/sofa-tracer-kafkamq-plugin/pom.xml (1)

8-8: Parent Version Update Confirmed
The parent version has been updated to 3.1.10-SNAPSHOT, which aligns with the new development snapshot across the project.

sofa-tracer-plugins/sofa-tracer-rocketmq-plugin/pom.xml (1)

8-8: Parent Version Synchronization
The parent version is correctly updated to 3.1.10-SNAPSHOT, ensuring consistency with other plugins and modules.

tracer-test/core-test/pom.xml (1)

4-9: Parent Version Update in Test Module
The parent version within this test project has been updated to 3.1.10-SNAPSHOT, which maintains consistency across the project. Verify that all dependent test configurations adjust accordingly.

sofa-tracer-plugins/sofa-tracer-mongodb-plugin/pom.xml (1)

8-8: Consistent Version Bump
The parent version is updated to 3.1.10-SNAPSHOT, ensuring uniformity across the plugin modules.

sofa-tracer-plugins/sofa-tracer-dubbo-2.6.x-plugin/pom.xml (1)

8-8: Parent Version Alignment
The parent version has been successfully bumped to 3.1.10-SNAPSHOT, matching the version updates in other parts of the project.

tracer-sofa-boot-starter/pom.xml (1)

8-8: Parent Version Update Confirmed.
The parent version is now set to <version>3.1.10-SNAPSHOT</version>, which aligns with the project's current development phase. Please verify that all modules referencing this parent are compatible with the snapshot update.

sofa-tracer-plugins/sofa-tracer-dubbo-common-plugin/pom.xml (1)

8-8: Parent Version Updated for Dubbo Common Plugin.
The updated version <version>3.1.10-SNAPSHOT</version> in the parent section ensures this module is aligned with the overall project versioning. Confirm that this change does not introduce conflicts with any referenced dependencies.

sofa-tracer-plugins/sofa-tracer-zipkin-plugin/pom.xml (1)

8-8: Consistent Parent Version in Zipkin Plugin.
The parent version update to <version>3.1.10-SNAPSHOT</version> is correctly applied. It maintains consistency with other modules, which is essential for coordinated builds.

sofa-tracer-plugins/sofa-tracer-spring-cloud-plugin/pom.xml (1)

8-8: Aligned Parent Version for Spring Cloud Plugin.
By updating the parent version to <version>3.1.10-SNAPSHOT</version>, this module remains in sync with the most recent development iteration. Ensure that any Spring Cloud related configurations are verified against this snapshot version.

sofa-tracer-plugins/sofa-tracer-flexible-plugin/pom.xml (1)

8-8: Snapshot Version Update for Flexible Plugin.
The parent tag now reflects <version>3.1.10-SNAPSHOT</version>, providing consistency across modules. It is recommended to run integration tests to ensure that the snapshot dependencies do not introduce unexpected behaviors.

sofa-tracer-plugins/sofa-tracer-dubbo-plugin/pom.xml (1)

8-8: Version Update Verified.
The parent version has been updated to <version>3.1.10-SNAPSHOT</version>, which aligns this module with the new development snapshot. This change is consistent with similar updates across the project.

sofa-tracer-plugins/sofa-tracer-resttmplate-plugin/pom.xml (1)

8-8: Parent Version Update Approved.
The update of the parent artifact version to <version>3.1.10-SNAPSHOT</version> is correctly applied here. Please ensure that all dependency and plugin configurations remain compatible with this new snapshot.

sofa-tracer-plugins/sofa-tracer-springmessage-plugin/pom.xml (1)

8-8: Consistent Parent Version Update.
The change to <version>3.1.10-SNAPSHOT</version> in the parent configuration is in line with the updates made in other modules. No issues were detected.

sofa-tracer-plugins/sofa-tracer-datasource-plugin/pom.xml (1)

8-8: Parent Version Correctly Updated.
The parent version is now set to <version>3.1.10-SNAPSHOT</version>, ensuring that this plugin is consistent with the project-wide version bump.

pom.xml (1)

12-12: Project Version Update Confirmed.
The overall project version has been updated to <version>3.1.10-SNAPSHOT</version>, ensuring consistency across dependency management and module versioning. Please verify that all modules correctly reference this updated version.

sofa-tracer-plugins/sofa-tracer-httpclient-plugin/pom.xml (1)

8-8: Parent Version Update Applied Correctly.

The parent version is updated to 3.1.10-SNAPSHOT, ensuring consistency with the overall project version upgrade. Please verify that this change aligns with dependency management across related modules.

sofa-tracer-plugins/sofa-tracer-redis-plugin/pom.xml (1)

8-8: Consistent Parent Version Update.

The switch from 3.1.9 to 3.1.10-SNAPSHOT is properly applied here. Confirm that no downstream modules are adversely impacted by this version change.

tracer-all/pom.xml (2)

5-9: Parent POM Version Synchronization.

The parent version is updated to 3.1.10-SNAPSHOT, aligning with the recent project-wide version bump. This ensures that all inherited properties and dependency management are current.


12-13: Artifact Version Update Confirmed.

Updating the artifact’s own version to 3.1.10-SNAPSHOT maintains cohesion with the parent version. This change is straightforward and consistent with the release strategy.

sofa-tracer-plugins/sofa-tracer-rabbitmq-plugin/pom.xml (1)

8-8: Parent Version Update is Consistent.

The update to 3.1.10-SNAPSHOT for the parent artifact is correctly implemented. Make sure that relative paths and any optional configurations remain properly referenced.

tracer-core/pom.xml (1)

7-7: Parent Version Update Propagated.

The update in tracer-core/pom.xml to 3.1.10-SNAPSHOT ensures that the core module inherits the latest settings and dependency versions from the parent POM. Confirm that any modules relying on these core components are tested for compatibility.

sofa-tracer-plugins/sofa-tracer-okhttp-plugin/pom.xml (1)

8-8: Update Parent Version to 3.1.10-SNAPSHOT

The parent version has been correctly updated from the previous release version to 3.1.10-SNAPSHOT, aligning this module with the overall release cadence. Please ensure that all related modules are updated consistently.

tracer-core/src/test/java/com/alipay/common/tracer/core/tracertest/type/TracerTestLogEnum.java (1)

27-32: Good addition of the RPC_CLIENT_EVENT constant

The new RPC_CLIENT_EVENT enum constant follows the existing pattern and naming convention consistently. The reformatting of the RPC_SERVER constant also improves readability while maintaining functionality.

tracer-core/src/test/java/com/alipay/common/tracer/core/tracertest/SofaTracerTest.java (7)

25-25: Appropriate import for event reporting functionality

The addition of the SpanEventDiskReporter import aligns with the new event support functionality being added in this PR.


31-31: Appropriate import for event encoding functionality

The addition of the ClientSpanEventEncoder import supports the new event encoding functionality.


90-92: Well-structured builder integration

The addition of client and server event reporters to the SofaTracer.Builder configuration is clean and maintains the fluent builder pattern.


145-145: Appropriate test for event reporting

The addition of span.reportEvent() to the testReportSpan method allows testing of the event reporting feature alongside the regular span reporting.


173-173: Consistent testing approach

Including reportEvent() in the testIsDisableAllDigestLog test ensures event reporting is tested when digest logs are disabled.


193-193: Thorough testing of event reporting

Adding reportEvent() to the testIsDisableClientDigestLog method ensures event reporting is tested when client digest logs are disabled.


211-211: Complete coverage of event reporting scenarios

The addition of reportEvent() to the testClose method ensures event reporting is properly tested after the tracer is closed.

tracer-core/src/test/java/com/alipay/common/tracer/core/tracertest/encoder/ClientSpanEventEncoder.java (1)

23-26: Good implementation of the SpanEncoder interface

The class properly implements the SpanEncoder<SofaTracerSpan> interface, and the usage of XStringBuilder for building the encoded string is appropriate and consistent with other encoder implementations.

tracer-core/src/test/java/com/alipay/common/tracer/core/reporter/digest/event/SpanEventDiskReporterTest.java (4)

48-55: Well-structured test setup

The test setup method (before) properly initializes the SpanEventDiskReporter instance with the expected configuration parameters and a mock SofaTracerSpan. This is consistent with good testing practices.


57-90: Comprehensive testing of reporter functionality

These test methods provide good coverage of the basic functionality of the SpanEventDiskReporter class, testing the log type, rolling policy, log reserve config, context encoder, and report digest functionality.


92-110: Good concurrent initialization test

The testFixInitDigestFile method is a well-designed test for ensuring thread safety during file initialization. It:

  1. Creates a thread pool with a specific number of threads
  2. Uses a CountDownLatch to synchronize the test
  3. Verifies that only one log entry is created during concurrent initialization

This is particularly important for a reporter that might be accessed concurrently in production.


112-140: Well-implemented worker thread class

The WorkerInitThread inner class properly implements the Runnable interface and provides a clear implementation for the concurrent test. It:

  1. Stores required references in the constructor
  2. Properly implements the run method to process commands and count down the latch
  3. Creates and configures a test span for reporting

This class design is clean and focused on its testing purpose.

tracer-core/src/test/java/com/alipay/common/tracer/core/span/SofaTracerSpanTest.java (4)

25-25: Clean imports for new event support feature.

The imports for SpanEventDiskReporter and ClientSpanEventEncoder are correctly added to support the new event functionality being tested.

Also applies to: 28-28


61-62: Well-structured constants for event log types.

Constants for client and server event log types are properly defined, consistent with the existing coding style for log type constants.

Also applies to: 65-65


77-84: Good configuration of event reporters in the setup method.

The test setup appropriately initializes client and server event reporters, integrating them into the tracer builder. This ensures comprehensive testing of the new event functionality.


207-229: Comprehensive test coverage for event tag functionality.

The new test methods thoroughly validate the different types of event tags (string, number, boolean) that can be set on spans. Each test follows the proper assertion pattern, ensuring tags are correctly stored and retrieved.

tracer-core/src/main/java/com/alipay/common/tracer/core/span/SofaTracerSpan.java (4)

73-77: Well-designed event tag storage.

The addition of map fields for event tags follows the same pattern as existing tag maps, providing consistent and type-safe storage for different event tag types.


190-200: Robust event reporting implementation.

The reportEvent() method properly checks if the span is closed before attempting to report an event. This prevents errors from reporting events on closed spans and provides appropriate error logging.


243-283: Well-implemented event tag methods.

The three event tag methods (setEventTag for String, boolean, and Number) are implemented correctly with appropriate null/blank checks, consistent with the existing tag methods. Each method correctly returns this for method chaining.


563-589: Comprehensive getter methods for event tags.

The getter methods for event tags are well-implemented and follow the same pattern as the existing getter methods for regular tags, providing consistent access to the event tag maps.

tracer-core/src/main/java/com/alipay/common/tracer/core/SofaTracer.java (8)

79-81: Clear declaration of event reporter fields.

The new event reporter fields are properly declared as final, consistent with the existing reporter fields, ensuring thread safety and indicating their immutability after initialization.


98-112: Proper initialization in existing constructors.

The existing constructors correctly initialize the new event reporter fields to null, maintaining backward compatibility with code that uses these constructors.


115-126: Well-designed new constructor supporting event reporters.

The new constructor properly initializes all fields, including the new event reporters, allowing clients to create a tracer with event reporting capability.


177-200: Consistent event reporting implementation.

The reportEvent method follows the same pattern as the existing reportSpan method, providing a consistent approach to handling both regular spans and event spans.


213-219: Proper resource cleanup for event reporters.

The close method is correctly updated to close the event reporters when they exist, ensuring proper resource cleanup.


238-244: Appropriate getter methods for event reporters.

The getter methods for event reporters follow the same pattern as the existing getter methods, providing consistent access to the reporter instances.


465-467: Builder pattern correctly extended for event reporters.

The builder class is properly extended with methods for setting event reporters, maintaining the fluent interface pattern and making it easy to configure a tracer with event reporting capability.

Also applies to: 488-496


551-552: Updated build method to use new constructor.

The build method correctly creates a new SofaTracer instance using the constructor that supports event reporters, ensuring that all configured components are properly initialized.

tracer-core/src/main/java/com/alipay/common/tracer/core/reporter/digest/event/SpanEventDiskReporter.java (4)

28-41: Well-structured class fields.

The fields are appropriately declared as final where applicable, and the use of AtomicBoolean for thread-safe initialization is a good practice.


52-60: Good constructor implementation with proper validation.

The constructor properly validates that the eventLogType is not empty using AssertUtils, which is a good practice to fail fast if invalid parameters are provided.


89-102: Properly implemented digestReport method with lazy initialization.

The digestReport method uses lazy initialization of the event file, which is an efficient approach. It also properly checks if the appender and encoder exist before attempting to append the span.


148-176: Thread-safe file initialization.

The initDigestFile method is correctly synchronized to ensure thread safety during file initialization. The double-check pattern is also used correctly to avoid unnecessary synchronization.

Comment on lines +1 to +4
/**
* Ant Group
* Copyright (c) 2004-2025 All Rights Reserved.
*/
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Update the license header

The current header uses "Ant Group Copyright" which doesn't match the Apache License header used in other files in this project.

Replace with the standard Apache License header:

-/**
- * Ant Group
- * Copyright (c) 2004-2025 All Rights Reserved.
- */
+/*
+ * 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.
+ */
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
/**
* Ant Group
* Copyright (c) 2004-2025 All Rights Reserved.
*/
/*
* 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.
*/

Comment on lines +1 to +4
/**
* Ant Group
* Copyright (c) 2004-2025 All Rights Reserved.
*/
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Update the license header

Similar to the ClientSpanEventEncoder class, this file uses the "Ant Group Copyright" header rather than the Apache License header used in other project files.

Replace with the standard Apache License header:

-/**
- * Ant Group
- * Copyright (c) 2004-2025 All Rights Reserved.
- */
+/*
+ * 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.
+ */
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
/**
* Ant Group
* Copyright (c) 2004-2025 All Rights Reserved.
*/
/*
* 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.
*/

Comment on lines +253 to 260
@Test
public void testEvent() {
SofaTracerSpan span = (SofaTracerSpan) this.sofaTracer.buildSpan("testWithTimestamp")
.withStartTimestamp(111).start();
span.setEventTag("tag.key", "value");
span.setTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CLIENT);
span.reportEvent();
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Missing assertions in event reporting test.

The testEvent() method doesn't include any assertions to verify that the event was properly reported or processed. This makes it difficult to determine if the test successfully validates the functionality.

Consider adding assertions to verify the event was successfully reported, perhaps by checking log output or using a mock reporter that can track reported events:

@Test
public void testEvent() {
    SofaTracerSpan span = (SofaTracerSpan) this.sofaTracer.buildSpan("testWithTimestamp")
            .withStartTimestamp(111).start();
    span.setEventTag("tag.key", "value");
    span.setTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CLIENT);
    span.reportEvent();
+   
+   // Verify event was reported correctly
+   // Option 1: If using a mock reporter, verify it was called
+   // Option 2: Check if event data was properly logged
+   assertTrue("Event should be reported", /* verification logic */);
}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
@Test
public void testEvent() {
SofaTracerSpan span = (SofaTracerSpan) this.sofaTracer.buildSpan("testWithTimestamp")
.withStartTimestamp(111).start();
span.setEventTag("tag.key", "value");
span.setTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CLIENT);
span.reportEvent();
}
@Test
public void testEvent() {
SofaTracerSpan span = (SofaTracerSpan) this.sofaTracer.buildSpan("testWithTimestamp")
.withStartTimestamp(111).start();
span.setEventTag("tag.key", "value");
span.setTag(Tags.SPAN_KIND.getKey(), Tags.SPAN_KIND_CLIENT);
span.reportEvent();
// Verify event was reported correctly
// Option 1: If using a mock reporter, verify it was called
// Option 2: Check if event data was properly logged
assertTrue("Event should be reported", /* verification logic */);
}

Comment on lines +1 to +4
/**
* Ant Group
* Copyright (c) 2004-2025 All Rights Reserved.
*/
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Inconsistent license header.

The copyright notice "Ant Group" differs from the Apache Software Foundation license used in other project files. This could cause confusion about licensing and ownership.

Update the license header to match the Apache Software Foundation license used in other files:

-/**
- * Ant Group
- * Copyright (c) 2004-2025 All Rights Reserved.
- */
+/*
+ * 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.
+ */
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
/**
* Ant Group
* Copyright (c) 2004-2025 All Rights Reserved.
*/
/*
* 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.
*/

Comment on lines +153 to +163
if (StringUtils.isNotBlank(logNameKey)) {
String currentDigestLogReserveConfig = SofaTracerConfiguration
.getLogReserveConfig(logNameKey);
if (!currentDigestLogReserveConfig.equals(eventLogReserveConfig)) {
SelfLog.info("the lognamekey : " + logNameKey
+ " take effect. the old logreserveconfig is "
+ eventLogReserveConfig + " and " + "the new logreverseconfig is "
+ currentDigestLogReserveConfig);
eventLogReserveConfig = currentDigestLogReserveConfig;
}
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Potential null pointer exception in log reserve config handling.

The code checks if logNameKey is not blank and then calls SofaTracerConfiguration.getLogReserveConfig(logNameKey), but there's no null check for the returned value before using equals().

if (StringUtils.isNotBlank(logNameKey)) {
    String currentDigestLogReserveConfig = SofaTracerConfiguration
            .getLogReserveConfig(logNameKey);
-   if (!currentDigestLogReserveConfig.equals(eventLogReserveConfig)) {
+   if (currentDigestLogReserveConfig != null && !currentDigestLogReserveConfig.equals(eventLogReserveConfig)) {
        SelfLog.info("the lognamekey : " + logNameKey
                + " take effect. the old logreserveconfig is "
                + eventLogReserveConfig + " and " + "the new logreverseconfig is "
                + currentDigestLogReserveConfig);
        eventLogReserveConfig = currentDigestLogReserveConfig;
    }
}
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (StringUtils.isNotBlank(logNameKey)) {
String currentDigestLogReserveConfig = SofaTracerConfiguration
.getLogReserveConfig(logNameKey);
if (!currentDigestLogReserveConfig.equals(eventLogReserveConfig)) {
SelfLog.info("the lognamekey : " + logNameKey
+ " take effect. the old logreserveconfig is "
+ eventLogReserveConfig + " and " + "the new logreverseconfig is "
+ currentDigestLogReserveConfig);
eventLogReserveConfig = currentDigestLogReserveConfig;
}
}
if (StringUtils.isNotBlank(logNameKey)) {
String currentDigestLogReserveConfig = SofaTracerConfiguration
.getLogReserveConfig(logNameKey);
if (currentDigestLogReserveConfig != null && !currentDigestLogReserveConfig.equals(eventLogReserveConfig)) {
SelfLog.info("the lognamekey : " + logNameKey
+ " take effect. the old logreserveconfig is "
+ eventLogReserveConfig + " and " + "the new logreverseconfig is "
+ currentDigestLogReserveConfig);
eventLogReserveConfig = currentDigestLogReserveConfig;
}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant