Skip to content
This repository has been archived by the owner on Oct 3, 2023. It is now read-only.
This repository has been archived by the owner on Oct 3, 2023. It is now read-only.

Segfault during Trace #239

Open
Open
@iamacarpet

Description

I'm trying to load a tracer class, but loading any more than one method trace at a time results in a segfault.

My class, which results in the segfault:

<?php

namespace App\Trace;

use App\NetSuiteImporter;
use OpenCensus\Trace\Integrations\IntegrationInterface;

class NetSuiteImportTracer implements IntegrationInterface
{
    public static function load()
    {
        if (!extension_loaded('opencensus')) {
            trigger_error('opencensus extension required to load Laravel integrations.', E_USER_WARNING);
            return;
        }

        opencensus_trace_method(NetSuiteImporter::class, 'import', [self::class, 'handleImport']);
        opencensus_trace_method(NetSuiteImporter::class, 'associations', [self::class, 'handleAssociations']);
        opencensus_trace_method(NetSuiteImporter::class, 'affiliates', [self::class, 'handleTest']);
        opencensus_trace_method(NetSuiteImporter::class, 'colours', [self::class, 'handleColours']);
        opencensus_trace_method(NetSuiteImporter::class, 'brands', [self::class, 'handleBrands']);
        opencensus_trace_method(NetSuiteImporter::class, 'product_segments', [self::class, 'handleProductSegments']);
        opencensus_trace_method(NetSuiteImporter::class, 'tariff_plans', [self::class, 'handleTariffPlans']);
        opencensus_trace_method(NetSuiteImporter::class, 'tariff_features', [self::class, 'handleTariffFeatures']);
        opencensus_trace_method(NetSuiteImporter::class, 'tariff_plan_features', [self::class, 'handleTariffPlanFeatures']);
        opencensus_trace_method(NetSuiteImporter::class, 'networks', [self::class, 'handleNetworks']);
        opencensus_trace_method(NetSuiteImporter::class, 'insurance', [self::class, 'handleInsurance']);
        opencensus_trace_method(NetSuiteImporter::class, 'finance', [self::class, 'handleFinance']);
        opencensus_trace_method(NetSuiteImporter::class, 'tradein', [self::class, 'handleTradein']);
        opencensus_trace_method(NetSuiteImporter::class, 'base_phones', [self::class, 'handleBasePhones']);
        opencensus_trace_method(NetSuiteImporter::class, 'tariffs', [self::class, 'handleTariffs']);
        opencensus_trace_method(NetSuiteImporter::class, 'tariff_addons', [self::class, 'handleTariffAddons']);
        opencensus_trace_method(NetSuiteImporter::class, 'accessories', [self::class, 'handleAccessories']);
        opencensus_trace_method(NetSuiteImporter::class, 'gifts', [self::class, 'handleGifts']);
        opencensus_trace_method(NetSuiteImporter::class, 'spend_caps', [self::class, 'handleSpendCaps']);
        opencensus_trace_method(NetSuiteImporter::class, 'spend_cap_options', [self::class, 'handleSpendCapOptions']);*/
    }

    public static function formatSize($size)
    {
        $unit=array('B','KB','MB','GB','TB','PB');
        return @round($size/pow(1024,($i=floor(log($size,1024)))),2).' '.$unit[$i];
    }

    public static function getAttributes()
    {
        return [
            'memory_usage' => self::formatSize(memory_get_usage(true)),
            'memory_usage_peak' => self::formatSize(memory_get_peak_usage(true)),
            'gc_enabled' => gc_enabled(),
            'gc_collect_cycles' => gc_collect_cycles(),
        ];
    }

    public static function handleImport($scope, $data)
    {
        return [
            'name' => 'memory/NetSuiteImporter/import',
            'attributes' => self::getAttributes(),
        ];
    }

    public static function handleAssociations($scope)
    {
        return [
            'name' => 'memory/NetSuiteImporter/associations',
            'attributes' => self::getAttributes(),
        ];
    }

    public static function handleAffiliates($scope, $affiliates)
    {
        return [
            'name' => 'memory/NetSuiteImporter/affiliates',
            'attributes' => self::getAttributes(),
        ];
    }

    public static function handleColours($scope, $colours)
    {
        return [
            'name' => 'memory/NetSuiteImporter/colours',
            'attributes' => self::getAttributes(),
        ];
    }

    public static function handleBrands($scope, $brands)
    {
        return [
            'name' => 'memory/NetSuiteImporter/brands',
            'attributes' => self::getAttributes(),
        ];
    }

    public static function handleProductSegments($scope, $product_segments)
    {
        return [
            'name' => 'memory/NetSuiteImporter/product_segments',
            'attributes' => self::getAttributes(),
        ];
    }

    public static function handleTariffPlans($scope, $tariff_plans)
    {
        return [
            'name' => 'memory/NetSuiteImporter/tariff_plans',
            'attributes' => self::getAttributes(),
        ];
    }

    public static function handleTariffFeatures($scope, $tariff_features)
    {
        return [
            'name' => 'memory/NetSuiteImporter/tariff_features',
            'attributes' => self::getAttributes(),
        ];
    }

    public static function handleNetworks($scope, $networks)
    {
        return [
            'name' => 'memory/NetSuiteImporter/networks',
            'attributes' => self::getAttributes(),
        ];
    }

    public static function handleInsurance($scope, $insurance_products)
    {
        return [
            'name' => 'memory/NetSuiteImporter/insurance',
            'attributes' => self::getAttributes(),
        ];
    }

    public static function handleFinance($scope, $finance_products)
    {
        return [
            'name' => 'memory/NetSuiteImporter/finance',
            'attributes' => self::getAttributes(),
        ];
    }

    public static function handleTradein($scope, $tradein_products)
    {
        return [
            'name' => 'memory/NetSuiteImporter/tradein',
            'attributes' => self::getAttributes(),
        ];
    }

    public static function handleBasePhones($scope, $handsets)
    {
        return [
            'name' => 'memory/NetSuiteImporter/base_phones',
            'attributes' => self::getAttributes(),
        ];
    }

    public static function handleTariffs($scope, $tariffs)
    {
        return [
            'name' => 'memory/NetSuiteImporter/tariffs',
            'attributes' => self::getAttributes(),
        ];
    }

    public static function handleTariffAddons($scope, $addons)
    {
        return [
            'name' => 'memory/NetSuiteImporter/tariff_addons',
            'attributes' => self::getAttributes(),
        ];
    }

    public static function handleAccessories($scope, $accessories)
    {
        return [
            'name' => 'memory/NetSuiteImporter/accessories',
            'attributes' => self::getAttributes(),
        ];
    }

    public static function handleGifts($scope, $gifts)
    {
        return [
            'name' => 'memory/NetSuiteImporter/gifts',
            'attributes' => self::getAttributes(),
        ];
    }

    public static function handleSpendCaps($scope, $caps)
    {
        return [
            'name' => 'memory/NetSuiteImporter/spend_caps',
            'attributes' => self::getAttributes(),
        ];
    }

    public static function handleSpendCapOptions($scope, $options)
    {
        return [
            'name' => 'memory/NetSuiteImporter/spend_cap_options',
            'attributes' => self::getAttributes(),
        ];
    }
}

You can make it work by commenting out all by one of the opencensus_trace_method lines in the load() function.

I'm confused because all the default tracing from https://github.com/a1comms/GaeSupportLaravel is loaded & reporting in Stackdriver expected and I can't spot any differences between those classes & this one. I've even made sure the callback function definitions match the parameters in the real functions.

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions