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

HttpServletRequest is not included in RequestTelemetryContext #1247

Closed
librucha opened this issue May 28, 2020 · 0 comments · Fixed by #1248
Closed

HttpServletRequest is not included in RequestTelemetryContext #1247

librucha opened this issue May 28, 2020 · 0 comments · Fixed by #1248
Assignees

Comments

@librucha
Copy link
Contributor

Expected behavior

ThreadContext.getRequestTelemetryContext().getHttpServletRequest() returns current servlet request if is implementation of HttpServletRequest

Actual behavior

returns always null

To Reproduce

Steps to reproduce the behavior:
Create own Telemetry initializer
in onInitializeTelemetry call ThreadContext.getRequestTelemetryContext().getHttpServletRequest()

Sample Application

@FieldDefaults(level = PRIVATE, makeFinal = true)
@RequiredArgsConstructor
public class OwnTelemetryInitializer extends WebTelemetryInitializerBase {

    @Override
    protected void onInitializeTelemetry(Telemetry telemetry) {

        Optional.ofNullable(ThreadContext.getRequestTelemetryContext())
                .map(RequestTelemetryContext::getHttpServletRequest)
                .map(HttpServletRequest::getRemoteAddr)
                .ifPresent(
                        clientIp -> telemetry.getContext().getLocation().setIp(clientIp)
                );
    }
}

System information

Please provide the following information:

  • SDK Version: 2.6.0
  • OS type and version: MacOS Catalina 10.15.4
  • Using spring-boot? YES
  • Additional relevant libraries (with version, if applicable):
librucha added a commit to librucha/ApplicationInsights-Java that referenced this issue May 28, 2020

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
@littleaj littleaj self-assigned this May 28, 2020
littleaj added a commit that referenced this issue Jul 9, 2020

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
[#1247] Fixed RequestTelemetryContext initialization
trask pushed a commit that referenced this issue Oct 17, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Jul 20, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants