Commit 1a77fd15 authored by Mark Harding's avatar Mark Harding
Browse files

(feat): implements sentry for php

parent dffd0a4e
Loading
Loading
Loading
Loading
+31 −2
Original line number Diff line number Diff line
@@ -40,7 +40,13 @@ prepare:fpm:
  image: minds/ci:latest
  script:
    - docker login -u gitlab-ci-token -p ${CI_BUILD_TOKEN} ${CI_REGISTRY} 
    - docker build -t $CI_REGISTRY_IMAGE/fpm:$CI_BUILD_REF -f containers/php-fpm/Dockerfile .
    - |
      docker build \
        -t $CI_REGISTRY_IMAGE/fpm:$CI_BUILD_REF \
        -f containers/php-fpm/Dockerfile \
        --build-arg MINDS_VERSION=$CI_BUILD_REF \
        --build-arg MINDS_VERSION=$SENTRY_DSN \
        .
    - docker push $CI_REGISTRY_IMAGE/fpm:$CI_BUILD_REF

prepare:runners:
@@ -48,9 +54,25 @@ prepare:runners:
  image: minds/ci:latest
  script:
    - docker login -u gitlab-ci-token -p ${CI_BUILD_TOKEN} ${CI_REGISTRY}
    - docker build -t $CI_REGISTRY_IMAGE/runners:$CI_BUILD_REF -f containers/php-runners/Dockerfile .
    - |
      docker build \
        -t $CI_REGISTRY_IMAGE/runners:$CI_BUILD_REF \
        -f containers/php-runners/Dockerfile \
        --build-arg MINDS_VERSION=$CI_BUILD_REF \
        --build-arg MINDS_VERSION=$SENTRY_DSN \
        .
    - docker push $CI_REGISTRY_IMAGE/runners:$CI_BUILD_REF

prepare:all:sentry:
  stage: prepare
  image: getsentry/sentry-cli
  script:
    - echo "Create a new release $CI_COMMIT_SHA"
    - sentry-cli releases new $CI_COMMIT_SHA
    - sentry-cli releases set-commits --auto $CI_COMMIT_SHA
    - sentry-cli releases finalize $CI_COMMIT_SHA
    - echo "Finalized release for $CI_COMMIT_SHA"

review:start:
  stage: review
  image: minds/helm-eks:latest
@@ -69,6 +91,7 @@ review:start:
        --wait \
        $CI_BUILD_REF_SLUG \
        ./helm-charts/minds"
    - sentry-cli releases deploys $CI_COMMIT_SHA new -e $CI_COMMIT_REF_NAME
  environment:
    name: review/$CI_COMMIT_REF_NAME
    url: https://$CI_BUILD_REF_SLUG.$KUBE_INGRESS_BASE_DOMAIN
@@ -112,6 +135,8 @@ staging:fpm:
    - docker push $CI_REGISTRY_IMAGE/fpm:$IMAGE_LABEL
    # Deploy to staging
    - aws ecs update-service --service=$ECS_APP_STAGING_SERVICE --force-new-deployment --region us-east-1 --cluster=$ECS_CLUSTER
    # Update sentry
    - sentry-cli releases deploys $CI_COMMIT_SHA new -e $IMAGE_LABEL
  environment:
    name: staging
    url: https://www.minds.com/?staging=1
@@ -136,6 +161,8 @@ canary:fpm:
    - docker push $CI_REGISTRY_IMAGE/fpm:$IMAGE_LABEL
    # Deploy to ECS
    - aws ecs update-service --service=$ECS_APP_CANARY_SERVICE --force-new-deployment --region us-east-1 --cluster=$ECS_CLUSTER
    # Update sentry
    - sentry-cli releases deploys $CI_COMMIT_SHA new -e $IMAGE_LABEL
  only:
    refs:
      - master
@@ -162,6 +189,8 @@ production:fpm:
    - docker push $CI_REGISTRY_IMAGE/fpm:$IMAGE_LABEL
    # Delpoy to ECS
    - aws ecs update-service --service=$ECS_APP_PRODUCTION_SERVICE --force-new-deployment --region us-east-1 --cluster=$ECS_CLUSTER
    # Update sentry
    - sentry-cli releases deploys $CI_COMMIT_SHA new -e $IMAGE_LABEL
  only:
    refs:
      - master
+25 −0
Original line number Diff line number Diff line
<?php
namespace Minds\Core\Sessions\Delegates;

use Sentry;
use Minds\Core\Sessions\Session;

class SentryScopeDelegate
{

    /**
     * Pass through a user guid to sentry
     * @param Session $session
     * @return void
     */
    public function onSession(Session $session): void
    {
        Sentry\configureScope(function (Sentry\State\Scope $scope) use ($session): void {
            $scope->setUser([
                'id' => (string) $session->getUserGuid(),
            ]);
        });
    }

}
+9 −1
Original line number Diff line number Diff line
@@ -23,6 +23,9 @@ class Manager
    /** @var Cookie $cookie */
    private $cookie;

    /** @var SentryScopeDelegate $sentryScopeDelegate */
    private $sentryScopeDelegate;

    /** @var Session $session */
    private $session;

@@ -34,7 +37,8 @@ class Manager
        $config = null,
        $cookie = null,
        $jwtBuilder = null,
        $jwtParser = null
        $jwtParser = null,
        $sentryScopeDelegate = null
    )
    {
        $this->repository = $repository ?: new Repository;
@@ -42,6 +46,7 @@ class Manager
        $this->cookie = $cookie ?: new Cookie;
        $this->jwtBuilder = $jwtBuilder ?: new JWT\Builder;
        $this->jwtParser = $jwtParser ?: new JWT\Parser;
        $this->sentryScopeDelegate = $sentryScopeDelegate ?? new Delegates\SentryScopeDelegate;
    }

    /**
@@ -124,6 +129,9 @@ class Manager
        // Hack, needs refactoring
        Core\Session::generateJWTCookie($session);

        // Allow Sentry to attach user metadata
        $this->sentryScopeDelegate->onSession($session);

        return $this;
    }

+3 −3
Original line number Diff line number Diff line
@@ -32,7 +32,8 @@
        "erusev/parsedown": "^1.7",
        "zendframework/zend-diactoros": "1.8.6",
        "league/oauth2-server": "7.2.0",
        "lcobucci/jwt": "3.2.4"
        "lcobucci/jwt": "3.2.4",
        "sentry/sdk": "2.0.3"
    },
    "repositories": [
        {
@@ -64,7 +65,6 @@
        "phpspec/phpspec": "~3.4",
        "leanphp/phpspec-code-coverage": "~3.1",
        "friendsofphp/php-cs-fixer": "*",
        "bossa/phpspec2-expect": "*",
        "apigen/apigen": "*"
        "bossa/phpspec2-expect": "*"
    }
}
+1489 −2334

File changed.

Preview size limit exceeded, changes collapsed.

Loading