Giter Site home page Giter Site logo

Comments (4)

splittingred avatar splittingred commented on July 24, 2024

There's not out of the box. It might be a good option. That said, you could fairly easily create a custom formatter:

require 'gruf'

class MyCustomFormatter < Gruf::Interceptors::Instrumentation::RequestLogging::Formatters::Base
  def format(payload)
    # do custom payload things here
    payload.merge!(format: 'json')
    payload.to_json
  end
end

Gruf.configure do |c|
  c.interceptors.use(
    Gruf::Interceptors::Instrumentation::RequestLogging::Interceptor,
    formatter: MyCustomFormatter
  )
end

from gruf.

zinosama avatar zinosama commented on July 24, 2024

There's not out of the box. It might be a good option. That said, you could fairly easily create a custom formatter:

require 'gruf'

class MyCustomFormatter < Gruf::Interceptors::Instrumentation::RequestLogging::Formatters::Base
  def format(payload)
    # do custom payload things here
    payload.merge!(format: 'json')
    payload.to_json
  end
end

Gruf.configure do |c|
  c.interceptors.use(
    Gruf::Interceptors::Instrumentation::RequestLogging::Interceptor,
    formatter: MyCustomFormatter
  )
end

Thanks for the quick response. Though in my use case, I actually need to insert data from the response/result instead of simple static values.

A good example of what Iā€™m looking for is the custom_payload option for lograge:

Rails.application.configure do
  config.lograge.enabled = true

  config.lograge.custom_payload do |controller|
    {
      host: controller.request.host,
      user_id: controller.current_user.try(:id)
    }
  end
end

from gruf.

splittingred avatar splittingred commented on July 24, 2024

Got it. There's a couple of ways we could solve this:

  • Create another configuration option that allows a block to be passed.
  • Pass the request object into formatters to allow them access.

I think i'd prefer the latter, as that doesn't introduce a new abstraction layer or configuration element, and allows custom formatters more flexibility and options when dealing with data. Thoughts?

from gruf.

zinosama avatar zinosama commented on July 24, 2024

Got it. There's a couple of ways we could solve this:

  • Create another configuration option that allows a block to be passed.
  • Pass the request object into formatters to allow them access.

I think i'd prefer the latter, as that doesn't introduce a new abstraction layer or configuration element, and allows custom formatters more flexibility and options when dealing with data. Thoughts?

I agree the latter is a better approach. It'd be weird to have gruf config options that are specific to an optional interceptor. Thanks for the quick response and getting this into PR.

from gruf.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    šŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. šŸ“ŠšŸ“ˆšŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ā¤ļø Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.