Coder Social home page Coder Social logo

Comments (15)

tmatsuo avatar tmatsuo commented on August 11, 2024

@steren Thanks for the report, I have few questions.

What happens with the first code? Is the log lost? Is it stored, but in the wrong format?

appropriate format

Where is it defined? The sample you showed seems weird, because it always says PHP Notice.
Why is the string "PHP Notice: " required?

If you have a plan for fixing this, can you share the details of your plan? ETA, how will you fix, etc?

Thanks!

from php-docs-samples.

steren avatar steren commented on August 11, 2024

This sample is used for Error Reporting documentation, not for Logging.

In the first code, the error is just stored in Logs, but not processed by Error Reporting because it is not in the expected format.

While waiting for Error Reporting to be more flexible in its error parsing (no ETA yet), we should adapt our samples to what Error Reporting is able to parse today. "PHP Notice" is required to fit the current parser.

The exception format is not documented, the idea is that Error Reporting is supposed to process default exception format.

Keeping a broken sample doesn't make sense and is very misleading. We will update it again later once the parser is updated.

from php-docs-samples.

tmatsuo avatar tmatsuo commented on August 11, 2024

@steren
Then how about turn down the sample? Isn't it also confusing we keep changing our samples?

from php-docs-samples.

steren avatar steren commented on August 11, 2024

GCE support is in Beta, it is OK to change our sample over time.

The fix I suggest has unblocked a customer who uses PHP.

I do not understand this push back and why we would not document how to use Error Reporting with PHP, knowing we have a workaround to the parser limitation

from php-docs-samples.

tmatsuo avatar tmatsuo commented on August 11, 2024

The reason I'm hesitant is because the string "PHP Notice:" looks really weird.
@bshaffer WDYT?

from php-docs-samples.

steren avatar steren commented on August 11, 2024

I agree it looks weird, we can add a comment explaining that it is due to a limitation of the Error Reporting service and will change in the future.

from php-docs-samples.

bshaffer avatar bshaffer commented on August 11, 2024

Yeah, this is a pretty unfortunate solution. What if Exception is a fatal error? We are logging it as a Notice, which is considered a lower level than Warning.

If anything, these errors should be logged as Emergency, as an exception handler indicates a 500 error. @steren Is there another option here, or is Notice the only way?

from php-docs-samples.

steren avatar steren commented on August 11, 2024

Here are the current prefixes that will be identified by the parser: PHP (Notice|Parse error|Fatal error|Warning):. We can pick any of this list at the moment, maybe Warning is better suited?

But note that the log entry severity is decorrelated from this. The severity can be set with the severity attribute.

So I suggest to update to:

$msg = array(
        'message' => sprintf("PHP Warning: %s", (string)$e),
        'serviceContext' => array('service' => 'myapp'),
        'severity'=>'ERROR'
        // ... add more metadata
    );

from php-docs-samples.

steren avatar steren commented on August 11, 2024

If everything goes well, the parser fix should be deployed by the end of the year or early next year. But in the meantime, I still think we should fix our broken sample.

from php-docs-samples.

tmatsuo avatar tmatsuo commented on August 11, 2024

@steren

I don't disagree that we should fix broken samples, but at the same time, we have finite resource. Considering the timing, the fix will be very short lived. We don't want to spend our time to write soon-to-be-thrown-away and looking-very-weird samples. So I suggested that we just turn down the sample and revive it when it just works.

However, what's the plan for the fix? Can we just pass the $e-getMessage() then will it work? Or will we still need to add some prefix?

That's why I wanted to know the future plans, specs etc.

The new sample you suggested look much nicer, so I'm not worried about the weirdness any more. We will fix it if time allows.

from php-docs-samples.

steren avatar steren commented on August 11, 2024

After the fix, you will need to pass 'message' => (string)$e,.

$e->getMessage() does not print a stack trace (and a stack trace is required for error grouping).

from php-docs-samples.

tmatsuo avatar tmatsuo commented on August 11, 2024

I think users should add severity if it matters, right?

from php-docs-samples.

steren avatar steren commented on August 11, 2024

Yes, adding a severity in the payload probably is better for users. But is not a hard requirement for errors to be processed.

So after the parser fix, the sample should be:

$msg = array(
        'message' => (string)$e,
        'serviceContext' => array('service' => 'myapp'),
        'severity'=>'ERROR'
        // ... add more metadata
    );

from php-docs-samples.

chooh avatar chooh commented on August 11, 2024

(ಠ_ಠ)

 self::fluentLogger()->post('errors', [
   'serviceContext' => ['service' => 'balance-checker'],
-  'message' => $e->getMessage() . PHP_EOL . "Stack trace:" . PHP_EOL . $e->getTraceAsString(),
+  'message' => str_replace('warning', 'Warning', $e->getMessage()) . PHP_EOL . "Stack trace:" . PHP_EOL . $e->getTraceAsString(),
 ]);

After this patch it finally worked.

from php-docs-samples.

steren avatar steren commented on August 11, 2024

Thanks. The second sample I provided in my original report should work too since the parser still expects this prefix: PHP (Notice|Parse error|Fatal error|Warning)

from php-docs-samples.

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.