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

cant produce api request log data #553

Open
Cuizhangqiang opened this issue Jul 10, 2024 · 10 comments
Open

cant produce api request log data #553

Cuizhangqiang opened this issue Jul 10, 2024 · 10 comments
Assignees
Labels
api API support bug Something isn't working logs Logs feature or improvement

Comments

@Cuizhangqiang
Copy link

cant produce api request log data

let networkInstrumentation = URLSessionInstrumentation(configuration: URLSessionInstrumentationConfiguration())

we use Alamofire Make network request

@Cuizhangqiang
Copy link
Author

URLSessionLogger.runningSpans always 0 elements

@Cuizhangqiang
Copy link
Author

截屏2024-07-12 17 17 03

@nachoBonafonte
Copy link
Member

The library is probably not identifying the Alamofire created URL session, I think it did in the past so probably Alamofire has updated something and we have lost visibility.

In URLSessionInstrumentation line 329 there is some code to handle it, explicitly in line 341, can you check if it is properly entering there and af_resume is still the internal name the library uses?

If not we would need a basic sample app reproducing the issue in order to try to fix it.

@Cuizhangqiang
Copy link
Author

截屏2024-07-12 17 57 43
AFURLSessionManager and af_resume both not found in the library - Alamofire (= 5.9.1)

@nachoBonafonte
Copy link
Member

The library is then clearly outdated, we would need a sample app that reproduces the issue in order to add support. We are also open to contributions 😉

@Cuizhangqiang
Copy link
Author

In Alamofire 5, AFURLSessionManager and many of the classes and methods related to it have been refactored or removed. AFURLSessionManager is a core class in Alamofire 4 that handles all URLSession related tasks. However, with the release of Alamofire 5, the codebase has been simplified and refactored to better support Swift language features and a more modern API design.

In Alamofire 5, AFURLSessionManager was replaced by the Session class, which manages all request and response handling and underlying URLSession tasks.

In Alamofire 5, the af_resume method is deprecated because Alamofire's design has been refactored to better support Swift language features and simplify the management of network requests. In Alamofire 4, af_resume is a method in the AFURLSessionManager class that initiates a pending network request.

In Alamofire 5, it is no longer necessary to explicitly call the af_resume method to initiate network requests because all requests are initiated immediately upon creation. The new Session class manages the creation and execution of all requests, simplifying the API and improving ease of use.

@Cuizhangqiang
Copy link
Author

I don't know how to fix the code to solve the problem I am currently experiencing, if there is an update on openmetry-swift, please let me know here, thank you very much 🙏

@nachoBonafonte
Copy link
Member

As said previously, if you can provide a sample project with a minimum setup that reproduces the issue it will help a lot to have it solved, because it removes the barrier of setting up a project to anyone willing to help.

@Cuizhangqiang
Copy link
Author

URLSessionInstrumentation+Alamofire.zip
Currently, I created a new project and only imported Alamofire and opentelemetry-swift. I found that the console kept outputting logs after starting the project. Please help me see if this is a bug.Open and run the above file to reproduce,Thank you!🙏
截屏2024-07-17 18 40 17

@alolita alolita added logs Logs feature or improvement api API support bug Something isn't working labels Jul 23, 2024
@bryce-b
Copy link
Member

bryce-b commented Aug 13, 2024

This is because you are using the SimpleSpanProcessor, which will trigger an export as soon as it processes any spans, combining this with the instrumented http exporter it causes an infinite loop. The SimpleSpanProcessor isn't intended to be used for anything more than testing. If you swap it out for a BatchSpanProcessor it will behave correctly.

If you used something like this :

      OpenTelemetry.registerTracerProvider(tracerProvider: TracerProviderBuilder()
          .add(spanProcessor: BatchSpanProcessor(spanExporter: otlpHttpTraceExporter, scheduleDelay: 60)) // 上报至可观测链路 OpenTelemetry 版
            .add(spanProcessor: spanProcessor)
            .with(resource: resource)
            .build())

It will prevent the repeated trace exports. This will limit the upload of spans to minutely

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api API support bug Something isn't working logs Logs feature or improvement
Projects
None yet
Development

No branches or pull requests

4 participants