kean / Pulse

Network logger for Apple platforms
https://pulselogger.com
MIT License
6.37k stars 311 forks source link

[Question] - Is it possible to customize the title of an item in the console? #306

Open TripwireNL opened 1 week ago

TripwireNL commented 1 week ago

Hi,

I'm using Pulse logger to log some custom messages for a new GraphQL implementation which works very well. The only downside is since every URL resolves against localhost:4000/graphql/ all the items in the console have /graphql/ and there's no way to differntiate which request is which (see attached image). Is it possible to customize this label?

Screenshot 2024-11-19 at 15 24 11

i'm using this code (Apollo client logging interceptor): `class LoggingInterceptor: ApolloInterceptor { var id: String = UUID().uuidString

func interceptAsync<Operation>(
    chain: any RequestChain,
    request: HTTPRequest<Operation>,
    response: HTTPResponse<Operation>?,
    completion: @escaping (Result<GraphQLResult<Operation.Data>, any Error>) -> Void
) where Operation: GraphQLOperation {
    guard let urlRequest = try? request.toURLRequest() else {
        print("GraphQL: We can't log anything without a valid request")
        return
    }

    let operationName = String(describing: request.operation)

    LoggerStore.shared.storeRequest(
        urlRequest,
        response: createURLResponse(response: response),
        error: nil,
        data: response?.rawData,
        metrics: nil,
        label: operationName,
        taskDescription: operationName
    )

    chain.proceedAsync(request: request, response: response, interceptor: self, completion: completion)
}

private func createURLResponse<Operation>(response: HTTPResponse<Operation>?) -> URLResponse? {
    guard let response = response, let responseURL = response.httpResponse.url else {
        return nil
    }

    let urlResponse = URLResponse(
        url: responseURL,
        mimeType: response.httpResponse.mimeType ?? "",
        expectedContentLength: Int(response.httpResponse.expectedContentLength),
        textEncodingName: response.httpResponse.textEncodingName ?? ""
    )

    return urlResponse
}

}`