Skip to content

chore: add logging for session and redis#614

Merged
Stream29 merged 1 commit into
mainfrom
chore/add-logs-for-session-and-redis
Feb 14, 2026
Merged

chore: add logging for session and redis#614
Stream29 merged 1 commit into
mainfrom
chore/add-logs-for-session-and-redis

Conversation

@Stream29

Copy link
Copy Markdown
Contributor

No description provided.

@Stream29 Stream29 requested a review from fatelei February 14, 2026 07:48
@dosubot dosubot Bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Feb 14, 2026
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @Stream29, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request significantly enhances the application's observability by integrating more detailed and context-aware logging across key session management and serverless transaction components. The changes focus on providing richer diagnostic information, such as session IDs, cache keys, and request contexts, for errors and warnings related to session caching and API request handling, making it easier to debug and monitor issues.

Highlights

  • Enhanced Error Logging for Session Cache Retrieval: Added detailed log.ErrorContext when failing to retrieve session information from the cache in the serverless transaction handler, including session_id, backwards_request_id, and the error.
  • Improved Error Logging for Response Writing: Updated error logging for failures when writing serverless transaction error responses, transitioning from log.Error to log.ErrorContext and adding session_id, backwards_request_id, and the error for better context.
  • Contextual Warning Logging for Dify Invocation Failures: Changed log.Warn to log.WarnContext for Dify invocation failures, now including the session_id and the error for more precise diagnostics.
  • Detailed Error Logging for Session Creation Cache Storage: Expanded error logging when setting new session information to the cache fails, using log.ErrorContext to include session_id, cache_key, cluster_id, plugin_unique_identifier, and the error.
  • Refined Error Logging for Session Deletion from Cache: Modified the session deletion logic to retrieve the session before removal, enabling log.ErrorContext to provide comprehensive details like session_id, cache_key, cluster_id, plugin_unique_identifier, and the error when cache deletion fails. It also handles cases where the session might not be found.
  • Warning for Missing Session ID Header: Introduced log.WarnContext to log a warning when the Dify-Plugin-Session-ID header is missing from incoming serverless transaction requests, providing method and path context.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • internal/core/io_tunnel/backwards_invocation/transaction/serverless_handler.go
    • Added detailed error logging when session info cannot be retrieved from cache.
    • Updated error logging for response write failures to include request context and specific identifiers.
    • Enhanced warning logging for Dify invocation failures with session ID context.
  • internal/core/session_manager/session.go
    • Improved error logging when storing new session information to cache fails, adding session and cache details.
    • Refactored session deletion to include more comprehensive error logging for cache removal, distinguishing between cases where session context is available or not.
  • internal/service/serverless_transaction.go
    • Added warning logging for requests missing the Dify-Plugin-Session-ID header.
    • Imported the log package.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request aims to improve logging by adding more context to log messages for session-related operations and Redis cache interactions, utilizing log.ErrorContext and log.WarnContext. However, a critical security vulnerability has been introduced: the logging of session_id and cache keys (which contain session IDs) leads to sensitive information leakage. Session IDs are sensitive tokens that can be used for user impersonation, and their exposure in logs poses a high security risk. These sensitive fields must be removed from log statements or properly masked before merging. Additionally, there's a potential issue with sessionId handling in serverless transactions; while a warning is logged for a missing Dify-Plugin-Session-ID header, the sessionId from this header is not correctly propagated to the core logic, which could lead to inconsistent behavior.

Comment on lines +92 to +98
log.ErrorContext(
ctx.Request.Context(),
"failed to get session info from cache",
"session_id", sessionId,
"backwards_request_id", backwardsRequestId,
"error", err,
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

security-high high

Logging the session_id is a security risk as session IDs are sensitive tokens that can be used to impersonate users. Exposing them in logs increases the risk of session hijacking if log files are accessed by unauthorized individuals or systems.

				log.ErrorContext(
					ctx.Request.Context(),
					"failed to get session info from cache",
					"backwards_request_id", backwardsRequestId,
					"error", err,
				)

Comment on lines +112 to +118
log.ErrorContext(
ctx.Request.Context(),
"failed to write serverless transaction error response",
"session_id", sessionId,
"backwards_request_id", backwardsRequestId,
"error", writeErr,
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

security-high high

Logging the session_id is a security risk as session IDs are sensitive tokens that can be used to impersonate users. Exposing them in logs increases the risk of session hijacking if log files are accessed by unauthorized individuals or systems.

					log.ErrorContext(
						ctx.Request.Context(),
						"failed to write serverless transaction error response",
						"backwards_request_id", backwardsRequestId,
						"error", writeErr,
					)

Comment on lines +150 to +155
log.WarnContext(
ctx.Request.Context(),
"invoke dify failed, received errors",
"session_id", sessionId,
"error", err,
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

security-high high

Logging the session_id is a security risk as session IDs are sensitive tokens that can be used to identify and authenticate user sessions. Exposing them in logs increases the risk of session hijacking.

			log.WarnContext(
				ctx.Request.Context(),
				"invoke dify failed, received errors",
				"error", err,
			)

Comment on lines +98 to +106
log.ErrorContext(
s.RequestContext(),
"set session info to cache failed",
"session_id", s.ID,
"cache_key", sessionKey(s.ID),
"cluster_id", s.ClusterID,
"plugin_unique_identifier", s.PluginUniqueIdentifier.String(),
"error", err,
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

security-high high

Logging the session_id and cache_key (which contains the session ID) is a security risk. Session IDs are sensitive tokens that should not be exposed in logs to prevent session hijacking.

			log.ErrorContext(
				s.RequestContext(),
				"set session info to cache failed",
				"cluster_id", s.ClusterID,
				"plugin_unique_identifier", s.PluginUniqueIdentifier.String(),
				"error", err,
			)

Comment on lines +158 to +166
log.ErrorContext(
session.RequestContext(),
"delete session info from cache failed",
"session_id", payload.ID,
"cache_key", cacheKey,
"cluster_id", session.ClusterID,
"plugin_unique_identifier", session.PluginUniqueIdentifier.String(),
"error", err,
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

security-high high

Logging the session_id and cache_key (which contains the session ID) is a security risk. Session IDs are sensitive tokens that should not be exposed in logs to prevent session hijacking.

				log.ErrorContext(
					session.RequestContext(),
					"delete session info from cache failed",
					"cluster_id", session.ClusterID,
					"plugin_unique_identifier", session.PluginUniqueIdentifier.String(),
					"error", err,
				)

Comment on lines +168 to +174
log.ErrorContext(
context.Background(),
"delete session info from cache failed",
"session_id", payload.ID,
"cache_key", cacheKey,
"error", err,
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

security-high high

Logging the session_id and cache_key (which contains the session ID) is a security risk. Session IDs are sensitive tokens that should not be exposed in logs to prevent session hijacking.

				log.ErrorContext(
					context.Background(),
					"delete session info from cache failed",
					"error", err,
				)

Comment on lines +13 to +20
if sessionId == "" {
log.WarnContext(
c.Request.Context(),
"missing Dify-Plugin-Session-ID header",
"method", c.Request.Method,
"path", c.Request.URL.Path,
)
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

While adding a warning for a missing Dify-Plugin-Session-ID header improves logging, the sessionId from the header is not consistently used in the downstream logic.

In internal/core/io_tunnel/backwards_invocation/transaction/serverless_handler.go, the sessionId is passed to the Handle function, but the subsequent call to plugin_entities.ParsePluginUniversalEvent hardcodes the session ID argument to an empty string "":

// internal/core/io_tunnel/backwards_invocation/transaction/serverless_handler.go:72
plugin_entities.ParsePluginUniversalEvent(
    bytes,
    "", // This is hardcoded
    ...
)

This forces the logic to always rely on the session ID from the request body's payload, making the Dify-Plugin-Session-ID header's value effectively ignored for the main session retrieval logic. The sessionId from the header is only used in a separate error logging path, which can cause confusion and hard-to-debug issues if the header and body session IDs differ.

To ensure consistent and predictable behavior, the sessionId from the header should be passed to ParsePluginUniversalEvent. The fix would be in serverless_handler.go to change line 72 to use the sessionId variable.

@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label Feb 14, 2026
@Stream29 Stream29 merged commit da9b7ae into main Feb 14, 2026
7 checks passed
@Stream29 Stream29 deleted the chore/add-logs-for-session-and-redis branch February 14, 2026 07:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

lgtm This PR has been approved by a maintainer plugin-daemon size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants